CF1820B.JoJo's Incredible Adventures

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Did you think there was going to be a JoJo legend here? But no, that was me, Dio!

Given a binary string ss of length nn, consisting of characters 0 and 1. Let's build a square table of size n×nn \times n, consisting of 0 and 1 characters as follows.

In the first row of the table write the original string ss. In the second row of the table write cyclic shift of the string ss by one to the right. In the third row of the table, write the cyclic shift of line ss by two to the right. And so on. Thus, the row with number kk will contain a cyclic shift of string ss by kk to the right. The rows are numbered from 00 to n−1n - 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)(i, j) in the table, such that x1≤i≤x2x_1 \le i \le x_2 and y1≤j≤y2y_1 \le j \le y_2 for some integers 0≤x1≤x2<n0 \le x_1 \le x_2 \lt n and 0≤y1≤y2<n0 \le y_1 \le y_2 \lt n.

Recall that the cyclic shift of string ss by kk to the right is the string sn−k+1…sns1s2…sn−ks_{n-k+1} \ldots s_n s_1 s_2 \ldots s_{n-k}. For example, the cyclic shift of the string "01011" by 00 to the right is the string itself "01011", its cyclic shift by 33 to the right is the string "01101".

你以为这里会有一个乔乔的传说吗?但其实是我,迪奥!

给定一个长度为 nn 的二进制字符串 ss,由字符 0 和 1 组成。我们按如下方式构造一个大小为 n×nn \times n 的、仅含 0 和 1 的方阵。

  • 在表格的第一行(即第 00 行)写入原始字符串 ss;
  • 在第二行(即第 11 行)写入字符串 ss 向右循环移动一位后的结果;
  • 在第三行(即第 22 行)写入字符串 ss 向右循环移动两位后的结果;
  • 依此类推……
    因此,第 kk 行(行号从 00 到 n−1n-1,自上而下编号)包含字符串 ss 向右循环移动 kk 位后的结果。

在该方阵中,我们需要找出全由 1 构成的矩形区域中面积最大的一个。

我们定义一个矩形为表格中所有满足 (i,j)(i, j) 的单元格构成的集合,其中 x1≤i≤x2x_1 \le i \le x_2 且 y1≤j≤y2y_1 \le j \le y_2,且 0≤x1≤x2<n0 \le x_1 \le x_2 < n、0≤y1≤y2<n0 \le y_1 \le y_2 < n。

注意:字符串 ss 向右循环移动 kk 位的定义为字符串

sn−k+1…sns1s2…sn−k.s_{n-k+1} \ldots s_n s_1 s_2 \ldots s_{n-k}.

例如,字符串 "01011" 向右循环移动 00 位的结果为其自身 "01011";向右循环移动 33 位的结果为 "01101"。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤2⋅1041 \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 ss (1≤∣s∣≤2⋅1051 \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∣|s| over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤2⋅1041 \le t \le 2 \cdot 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个二进制字符串 ss(1≤∣s∣≤2⋅1051 \le \lvert s \rvert \le 2 \cdot 10^5),该字符串仅由字符 0 和 1 组成。

保证所有测试用例中字符串长度 ∣s∣|s| 的总和不超过 2⋅1052 \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 00.

对于每个测试用例,输出一个整数——仅由数字 1 构成的矩形的最大面积。如果不存在这样的矩形,则输出 00。

输入输出样例

  • 输入#1

    5
    0
    1
    101
    011110
    101010

    输出#1

    0
    1
    2
    6
    1

说明/提示

In the first test case, there is a table 1×11 \times 1 consisting of a single character 0, so there are no rectangles consisting of ones, and the answer is 00.

In the second test case, there is a table 1×11 \times 1, consisting of a single character 1, so the answer is 11.

In the third test case, there is a table:

1

0

1

1

1

0

0

1

1

In the fourth test case, there is a table:

0

1

1

1

1

0

0

0

1

1

1

1

1

0

0

1

1

1

1

1

0

0

1

1

1

1

1

0

0

1

1

1

1

1

0

0

In the fifth test case, there is a table:

1

0

1

0

1

0

0

1

0

1

0

1

1

0

1

0

1

0

0

1

0

1

0

1

1

0

1

0

1

0

0

1

0

1

0

1

Rectangles with maximum area are shown in bold.

在第一个测试用例中,存在一个 1×11 \times 1 的表格,仅包含单个字符 0,因此不存在全由 1 组成的矩形,答案为 00。

在第二个测试用例中,存在一个 1×11 \times 1 的表格,仅包含单个字符 1,因此答案为 11。

在第三个测试用例中,存在如下表格:

1

0

1

1

1

0

0

1

1

在第四个测试用例中,存在如下表格:

0

1

1

1

1

0

0

0

1

1

1

1

1

0

0

1

1

1

1

1

0

0

1

1

1

1

1

0

0

1

1

1

1

1

0

0

在第五个测试用例中,存在如下表格:

1

0

1

0

1

0

0

1

0

1

0

1

1

0

1

0

1

0

0

1

0

1

0

1

1

0

1

0

1

0

0

1

0

1

0

1

面积最大的矩形以粗体标出。

输入解题思路,AI测评打分。不知道怎么写?

首页