CF1750B.Maximum Substring

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A binary string is a string consisting only of the characters 0 and 1. You are given a binary string ss .

For some non-empty substring ^\dagger tt of string ss containing xx characters 0 and yy characters 1, define its cost as:

  • xyx \cdot y , if x>0x > 0 and y>0y > 0 ;
  • x2x^2 , if x>0x > 0 and y=0y = 0 ;
  • y2y^2 , if x=0x = 0 and y>0y > 0 .

Given a binary string ss of length nn , find the maximum cost across all its non-empty substrings.

^\dagger A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt ( 1t1051 \leq t \leq 10^5 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the length of the string ss .

The second line of each test case contains a binary string ss of length nn .

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print a single integer — the maximum cost across all substrings.

输入输出样例

  • 输入#1

    6
    5
    11100
    7
    1100110
    6
    011110
    7
    1001010
    4
    1000
    1
    0

    输出#1

    9
    12
    16
    12
    9
    1

说明/提示

In the first test case, we can take a substring 111111 . It contains 33 characters 1 and 00 characters 0. So a=3a = 3 , b=0b = 0 and its cost is 32=93^2 = 9 .

In the second test case, we can take the whole string. It contains 44 characters 1 and 33 characters 0. So a=4a = 4 , b=3b = 3 and its cost is 43=124 \cdot 3 = 12 .

In the third test case, we can can take a substring 11111111 and its cost is 42=164^2 = 16 .

In the fourth test case, we can take the whole string and cost is 43=124 \cdot 3 = 12 .

In the fifth test case, we can take a substring 000000 and its cost is 33=93 \cdot 3 = 9 .

In the sixth test case, we can only take the substring 00 and its cost is 11=11 \cdot 1 = 1 .

首页