QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#13500. 分析(但特殊的)比特串

统计

你觉得分析 01 串很容易吗?但在梦境中可不是这样。

所以你现在处于梦境中。出乎意料,对吧?但是……恐怕这不是你一直想做的梦。在梦中你有一串 01 字符,不过,你需要处理的是一串很长的 01 字符。你清楚地知道现在该做什么才能离开这个可怕的梦境:找到最棒的特殊字符串(special string)。

幸运的是,你记得昨天读过一本关于特殊字符串理论的书。你只设法记住了关于特殊字符串最奇特的定义,其内容如下:

假设有一个长度为 $n$ 的 01 字符串 $T$。$T$ 的字符表示为 $T_1, T_2, \dots, T_n$。 我们用 $A(i, j)$ 和 $B(i, j)$ 分别表示 $T_i, T_{i+1}, \dots, T_j$ 中 0 字符和 1 字符的数量。 如果对于每个介于 $1$ 和 $n$ 之间(含)的 $i$,以下两个条件都成立,则称字符串 $T$ 是特殊的

  • $A(1, i) \ge B(1, i)$
  • $A(i, n) \le B(i, n)$

但你不能满足于任意一个特殊字符串。你需要最棒的特殊字符串。这个梦境非常诡异,因此决定两个字符串哪个更好的规则也很诡异。设 $L_1$ 和 $L_2$ 为两个字符串的长度,而 $P_1$ 和 $P_2$ 分别为它们在给定的字符串 $S$ 中作为子串出现的次数。那么,如果 $L_1 \cdot P_1 > L_2 \cdot P_2$,第一个字符串就比第二个更好。

所以你的任务很简单……或者不简单?找到最棒的特殊字符串 —— 即在 $S$ 的所有作为子串的特殊字符串中,没有其他特殊字符串比它更好。

输入格式

输入文件仅包含一行,为一个字符串 $S$($2 \le |S| \le 2 \cdot 10^5$)—— 由 0 和 1 组成的字符串。

输出格式

输出文件的第一行应包含 $L \cdot P$ 的值,其中 $L$ 是最棒的特殊字符串的长度,$P$ 是它作为子串在 $S$ 中出现的次数。

输出文件的第二行应包含该最棒的特殊字符串本身。如果有多个最棒的特殊字符串,你可以输出其中任意一个。

保证 $S$ 中至少存在一个特殊字符串作为其子串。

样例

输入样例 1

00111001110101

输出样例 1

8
0011

输入样例 2

00011001110101

输出样例 2

14
00011001110101

输入样例 3

0101010101

输出样例 3

18
010101

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.