A15942 | JoJo's Incredible Adventures
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Did you think there was going to be a JoJo legend here? But no, that was me, Dio!
Given a binary string $s$ of length $n$ , consisting of characters 0 and 1. Let's build a square table of size $n \times n$ , consisting of 0 and 1 characters as follows.
In the first row of the table write the original string $s$ . In the second row of the table write cyclic shift of the string $s$ by one to the right. In the third row of the table, write the cyclic shift of line $s$ by two to the right. And so on. Thus, the row with number $k$ will contain a cyclic shift of string $s$ by $k$ to the right. The rows are numbered from $0$ to $n - 1$ top-to-bottom.
In the resulting table we need to find the rectangle consisting only of ones that has the largest area.
We call a rectangle the set of all cells $(i, j)$ in the table, such that $x_1 \le i \le x_2$ and $y_1 \le j \le y_2$ for some integers $0 \le x_1 \le x_2 < n$ and $0 \le y_1 \le y_2 < n$ .
Recall that the cyclic shift of string $s$ by $k$ to the right is the string $s_{n-k+1} \ldots s_n s_1 s_2 \ldots s_{n-k}$ . For example, the cyclic shift of the string "01011" by $0$ to the right is the string itself "01011", its cyclic shift by $3$ to the right is the string "01101".
Given a binary string $s$ of length $n$ , consisting of characters 0 and 1. Let's build a square table of size $n \times n$ , consisting of 0 and 1 characters as follows.
In the first row of the table write the original string $s$ . In the second row of the table write cyclic shift of the string $s$ by one to the right. In the third row of the table, write the cyclic shift of line $s$ by two to the right. And so on. Thus, the row with number $k$ will contain a cyclic shift of string $s$ by $k$ to the right. The rows are numbered from $0$ to $n - 1$ top-to-bottom.
In the resulting table we need to find the rectangle consisting only of ones that has the largest area.
We call a rectangle the set of all cells $(i, j)$ in the table, such that $x_1 \le i \le x_2$ and $y_1 \le j \le y_2$ for some integers $0 \le x_1 \le x_2 < n$ and $0 \le y_1 \le y_2 < n$ .
Recall that the cyclic shift of string $s$ by $k$ to the right is the string $s_{n-k+1} \ldots s_n s_1 s_2 \ldots s_{n-k}$ . For example, the cyclic shift of the string "01011" by $0$ to the right is the string itself "01011", its cyclic shift by $3$ to the right is the string "01101".
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \le t \le 2 \cdot 10^4$ ) — the number of test cases. The description of test cases follows.
The first and the only line of each test case contains a single binary string $s$ ( $1 \le \lvert s \rvert \le 2 \cdot 10^5$ ), consisting of characters 0 and 1.
It is guaranteed that the sum of string lengths $|s|$ over all test cases does not exceed $2 \cdot 10^5$ .
The first and the only line of each test case contains a single binary string $s$ ( $1 \le \lvert s \rvert \le 2 \cdot 10^5$ ), consisting of characters 0 and 1.
It is guaranteed that the sum of string lengths $|s|$ over all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, output a single integer — the maximum area of a rectangle consisting only of ones. If there is no such rectangle, output $0$ .
输入输出样例
输入 #1
5 0 1 101 011110 101010
输出 #1
0 1 2 6 1
In the first test case, there is a table $1 \times 1$ consisting of a single character 0, so there are no rectangles consisting of ones, and the answer is $0$ .
In the second test case, there is a table $1 \times 1$ , consisting of a single character 1, so the answer is $1$ .
In the third test case, there is a table:
101110011In the fourth test case, there is a table:
011110001111100111110011111001111100In the fifth test case, there is a table:
101010010101101010010101101010010101Rectangles with maximum area are shown in bold.
In the second test case, there is a table $1 \times 1$ , consisting of a single character 1, so the answer is $1$ .
In the third test case, there is a table:
101110011In the fourth test case, there is a table:
011110001111100111110011111001111100In the fifth test case, there is a table:
101010010101101010010101101010010101Rectangles with maximum area are shown in bold.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted