CF827E.Rusty String

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was written.

Grigory couldn't understand for a long time what these letters remind him of, so he became interested in the following question: if we put a letter "V" or "K" on each unreadable position, which values can the period of the resulting string be equal to?

A period of a string is such an integer d from 1 to the length of the string that if we put the string shifted by d positions to the right on itself, then all overlapping letters coincide. For example, 3 and 5 are periods of "VKKVK".

格里戈里喜欢字符串。最近,他在阁楼上发现了一条金属条。该金属条长度为 nn,由字母 “V” 和 “K” 组成。不幸的是,部分字母已被锈蚀,因此现在无法辨认这些位置上原本是哪个字母。

格里戈里长时间想不起这些字母让他联想到什么,于是他对如下问题产生了兴趣:若在每个不可读的位置填入字母 “V” 或 “K”,那么最终字符串的周期可能取哪些值?

字符串的一个周期是指一个整数 dd(满足 1≤d≤1 \le d \le 字符串长度),使得将该字符串整体向右平移 dd 个位置后与原字符串重叠的部分中,所有对应位置上的字母均相同。例如,“VKKVK” 的周期包括 33 和 55。

输入格式

There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases.

There is an empty line before each test case. Each test case is described in two lines: the first line contains single integer n (1 ≤ n ≤ 5·105) — the length of the string, the second line contains the string of length n, consisting of letters "V", "K" and characters "?". The latter means the letter on its position is unreadable.

It is guaranteed that the sum of lengths among all test cases doesn't exceed 5·105.

For hacks you can only use tests with one test case.

输入包含若干个(至少一个)测试用例。第一行包含一个整数——测试用例的数量。

每个测试用例之前有一空行。每个测试用例由两行描述:第一行包含一个整数 nn(1 ≤ n ≤ 5⋅1051 \le n \le 5\cdot10^5)——字符串的长度;第二行包含一个长度为 nn 的字符串,由字母 "V"、"K" 和字符 "?" 组成。其中 "?" 表示该位置上的字母无法识别。

保证所有测试用例的字符串长度之和不超过 5⋅1055\cdot10^5。

对于 hack,你只能使用仅含一个测试用例的测试数据。

输出格式

For each test case print two lines. In the first line print the number of possible periods after we replace each unreadable letter with "V" or "K". In the next line print all these values in increasing order.

对每个测试用例,输出两行。第一行输出在将每个不可读字母替换为 "V" 或 "K" 后,可能的周期个数。第二行按升序输出所有这些周期值。

输入输出样例

  • 输入#1

    3
    
    5
    V??VK
    
    6
    ??????
    
    4
    ?VK?

    输出#1

    2
    3 5
    6
    1 2 3 4 5 6
    3
    2 3 4

说明/提示

In the first test case from example we can obtain, for example, "VKKVK", which has periods 3 and 5.

In the second test case we can obtain "VVVVVV" which has all periods from 1 to 6.

In the third test case string "KVKV" has periods 2 and 4, and string "KVKK" has periods 3 and 4.

在示例的第一个测试用例中,我们可以得到例如 "VKKVK",其具有周期 3 和 5。

在第二个测试用例中,我们可以得到 "VVVVVV",其具有从 1 到 6 的所有周期。

在第三个测试用例中,字符串 "KVKV" 具有周期 2 和 4,而字符串 "KVKK" 具有周期 3 和 4。

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

首页