AT_arc227_c.Follow the Letters
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string S of length N consisting of lowercase English letters. Let Si denote the i-th character of S.
There are N islands arranged in a circle, numbered island 1, island 2, …, island N in clockwise order. In particular, the island clockwise-adjacent to island N is island 1. The character Si is written on island i. Initially, there is one person on each island.
You can perform the following operation zero or more times.
- Choose one character c that appears in S. Every person departs from the island they are currently on and moves one island at a time in the clockwise direction. Each person stops as soon as they first arrive, after departing, at an island on which the character c is written. Even if the island a person is currently on has the character c written on it, that person still departs.
Let K be the minimum possible number of islands that have one or more people on them after all operations are finished.
Find K, and a sequence of operations that makes the number of islands with one or more people equal to K after the operations.
Under the constraints of this problem, it can be proved that there always exists a sequence of operations of length at most 106 that makes the number of islands with one or more people equal to K.
给你一个长度为 N 的字符串 S,其中仅包含小写英文字母。记 Si 为字符串 S 的第 i 个字符。
有 N 座岛屿按顺时针方向围成一圈,编号为岛屿 1、岛屿 2、…、岛屿 N。特别地,岛屿 N 顺时针方向的相邻岛屿是岛屿 1。岛屿 i 上写着字符 Si。初始时,每座岛屿上恰好有一个人。
你可以执行以下操作零次或多次:
- 选择一个在 S 中出现的字符 c。此时,所有当前位于某座岛屿上的人均离开该岛,并逐岛沿顺时针方向移动;每个人在离开起始岛屿后,首次到达一座写有字符 c 的岛屿时即停止。即使某人当前所在的岛屿上已写有字符 c,该人仍必须离开该岛。
设 K 为所有操作结束后,至少有一人的岛屿数量的最小可能值。
请找出该最小值 K,并构造一个操作序列,使得执行该序列后,至少有一人的岛屿数量恰好为 K。
在本题约束下,可以证明:总存在一个长度不超过 106 的操作序列,使得最终至少有一人的岛屿数量等于 K。
输入格式
The input is given from Standard Input in the following format:
N
S
输入从标准输入中按以下格式给出:
N
S
输出格式
Let L be an integer representing the number of operations, and let X be a string representing the sequence of operations. Output in the following format:
K
L
X
If L=0, output the third line as an empty line.
L must satisfy 0≤L≤106.
X must be a string of length L consisting of characters that appear in S, and the i-th character of X represents the character chosen in the i-th operation.
After performing the operations according to the sequence X, the number of islands with one or more people must be K.
If multiple outputs satisfy the conditions, you may output any of them.
设 L 为表示操作次数的整数,X 为表示操作序列的字符串。请按如下格式输出:
K
L
X
若 L=0,则第三行输出为空行。
L 必须满足 0≤L≤106。
X 必须是长度为 L 的字符串,其每个字符均来自集合 S;其中 X 的第 i 个字符表示第 i 次操作所选的字符。
按照操作序列 X 执行所有操作后,含有一人或以上人员的岛屿数量必须恰好为 K。
若存在多个满足条件的输出,可任选其一输出。
输入输出样例
输入#1
4 abca
输出#1
1 1 b
输入#2
4 aabb
输出#2
1 2 ab
输入#3
4 aaaa
输出#3
4 0
说明/提示
Sample 1 Explanation:
If we perform the operation choosing the character b, everyone gathers on the island on which the character b is written. The number of islands with people becomes 1, and this is the minimum.
Sample 2 Explanation:
By choosing a first and then b, everyone gathers on the same island. The number of islands with people becomes 1, and this is the minimum.
Sample 3 Explanation:
No matter which operation is performed, each person moves to the next island in the clockwise direction. Therefore, the number of islands with people is always 4, so K=4. In this sample output, no operation is performed.
Constraints
- 1≤N≤1000
- S is a string of length N consisting of lowercase English letters.
- N is an integer.
样例 1 解释:
如果我们执行选择字符 b 的操作,则所有人将聚集在写有字符 b 的岛屿上。此时有人居住的岛屿数量为 1,这是最小值。
样例 2 解释:
先选择 a,再选择 b,所有人将聚集在同一座岛屿上。此时有人居住的岛屿数量为 1,这是最小值。
样例 3 解释:
无论执行哪一种操作,每个人均会顺时针移动到下一座岛屿。因此,有人居住的岛屿数量恒为 4,故 K=4。本样例的输出中未执行任何操作。
约束条件
- 1≤N≤1000
- S 是一个长度为 N 的字符串,仅由小写英文字母组成。
- N 是一个整数。
输入解题思路,AI测评打分。不知道怎么写?