#P16841. [GKS 2021 #B] Increasing Substring

    ID: 19168 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>字符串动态规划 DP2021Google Kick Start

[GKS 2021 #B] Increasing Substring

Problem Description

Your friend John just came back from vacation, and he would like to share with you a new property that he learned about strings.

John learned that a string CC of length LL consisting of uppercase English characters is strictly increasing if, for every pair of indices ii and jj such that 1i<jL1 \le i < j \le L (11-based), the character at position ii is smaller than the character at position jj.

For example, the strings ABC and ADF are strictly increasing, however the strings ACC and FDA are not.

Now that he taught you this new exciting property, John decided to challenge you: given a string SS of length NN, you have to find out, for every position 1iN1 \le i \le N, what is the length of the longest strictly increasing substring that ends at position ii.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case consists of two lines.

The first line contains an integer NN, representing the length of the string.

The second line contains a string SS of length NN, consisting of uppercase English characters.

Output Format

For each test case, output one line containing Case #x: followed by y1 y2  yny_1\ y_2\ \ldots\ y_n, where xx is the test case number (starting from 11) and yiy_i is the length of the longest strictly increasing substring that ends at position ii.

2
4
ABBC
6
ABACDA
Case #1: 1 2 1 2
Case #2: 1 2 1 2 3 1

Hint

In Sample Case 11, the longest strictly increasing substring ending at position 11 is A. The longest strictly increasing substrings ending at positions 22, 33, and 44 are AB, B, and BC, respectively.

In Sample Case 22, the longest strictly increasing substrings for each position are A, AB, A, AC, ACD, and A.

Limits

1T1001 \le T \le 100.

Test Set 11

1N1001 \le N \le 100.

Test Set 22

1N2×1051 \le N \le 2 \times 10^5.