CF1043C.Smallest Word
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting.
Today, when IA looked at the fridge, she noticed that the word formed by magnets is really messy. "It would look much better when I'll swap some of them!" — thought the girl — "but how to do it?". After a while, she got an idea. IA will look at all prefixes with lengths from 1 to the length of the word and for each prefix she will either reverse this prefix or leave it as it is. She will consider the prefixes in the fixed order: from the shortest to the largest. She wants to get the lexicographically smallest possible word after she considers all prefixes. Can you help her, telling which prefixes should be chosen for reversing?
A string a is lexicographically smaller than a string b if and only if one of the following holds:
- a is a prefix of b, but a=b;
- in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
IA 的冰箱上有许多五颜六色的磁贴!每块磁贴上恰好写有一个字母,即 'a' 或 'b'。她很喜欢玩这些磁贴,把所有磁贴排成一排。然而,这个女孩很快就会感到厌倦,常常思考如何让自己的娱乐变得更有趣。
今天,当 IA 看向冰箱时,她注意到磁贴组成的单词看起来非常杂乱。“如果我交换其中一些磁贴,效果会好得多!”——女孩心想——“但该怎么做呢?”过了一会儿,她想到了一个主意。IA 将依次考察长度从 1 到整个单词长度的所有前缀;对每个前缀,她将选择将其反转,或保持原样不变。她将按固定顺序考虑这些前缀:从最短的到最长的。她的目标是在处理完所有前缀后,得到字典序最小的可能字符串。你能帮帮她吗?请指出哪些前缀应被选中进行反转。
字符串 a 字典序小于字符串 b,当且仅当满足以下条件之一:
- a 是 b 的前缀,但 a=b;
- 在 a 与 b 首次出现差异的位置上,a 中的字母在字母表中位于 b 中对应字母之前。
输入格式
The first and the only line contains a string s (1≤∣s∣≤1000), describing the initial string formed by magnets. The string s consists only of characters 'a' and 'b'.
第一行且唯一一行包含一个字符串 s(1≤∣s∣≤1000),描述由磁铁构成的初始字符串。字符串 s 仅由字符 'a' 和 'b' 组成。
输出格式
Output exactly ∣s∣ integers. If IA should reverse the i-th prefix (that is, the substring from 1 to i), the i-th integer should be equal to 1, and it should be equal to 0 otherwise.
If there are multiple possible sequences leading to the optimal answer, print any of them.
输出恰好 ∣s∣ 个整数。如果 IA 应该翻转第 i 个前缀(即从位置 1 到 i 的子串),则第 i 个整数应为 1;否则应为 0。
如果存在多个能得到最优答案的序列,输出其中任意一个即可。
输入输出样例
输入#1
bbab
输出#1
0 1 1 0
输入#2
aaaaa
输出#2
1 0 0 0 1
说明/提示
In the first example, IA can reverse the second and the third prefix and get a string "abbb". She cannot get better result, since it is also lexicographically smallest string obtainable by permuting characters of the initial string.
In the second example, she can reverse any subset of prefixes — all letters are 'a'.
在第一个例子中,IA 可以翻转第二个和第三个前缀,从而得到字符串 "abbb"。她无法得到更优的结果,因为该字符串同时也是对初始字符串的字符进行重排后所能得到的字典序最小的字符串。
在第二个例子中,她可以翻转任意一组前缀——所有字母均为 'a'。
输入解题思路,AI测评打分。不知道怎么写?