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 11 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 aa is lexicographically smaller than a string bb if and only if one of the following holds:

  • aa is a prefix of bb, but a≠ba \ne b;
  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

IA 的冰箱上有许多五颜六色的磁贴!每块磁贴上恰好写有一个字母,即 'a' 或 'b'。她很喜欢玩这些磁贴,把所有磁贴排成一排。然而,这个女孩很快就会感到厌倦,常常思考如何让自己的娱乐变得更有趣。

今天,当 IA 看向冰箱时,她注意到磁贴组成的单词看起来非常杂乱。“如果我交换其中一些磁贴,效果会好得多!”——女孩心想——“但该怎么做呢?”过了一会儿,她想到了一个主意。IA 将依次考察长度从 11 到整个单词长度的所有前缀;对每个前缀,她将选择将其反转,或保持原样不变。她将按固定顺序考虑这些前缀:从最短的到最长的。她的目标是在处理完所有前缀后,得到字典序最小的可能字符串。你能帮帮她吗?请指出哪些前缀应被选中进行反转。

字符串 aa 字典序小于字符串 bb,当且仅当满足以下条件之一:

  • aa 是 bb 的前缀,但 a≠ba \ne b;
  • 在 aa 与 bb 首次出现差异的位置上,aa 中的字母在字母表中位于 bb 中对应字母之前。

输入格式

The first and the only line contains a string ss (1≤∣s∣≤10001 \le |s| \le 1000), describing the initial string formed by magnets. The string ss consists only of characters 'a' and 'b'.

第一行且唯一一行包含一个字符串 ss(1≤∣s∣≤10001 \le |s| \le 1000),描述由磁铁构成的初始字符串。字符串 ss 仅由字符 'a' 和 'b' 组成。

输出格式

Output exactly ∣s∣|s| integers. If IA should reverse the ii-th prefix (that is, the substring from 11 to ii), the ii-th integer should be equal to 11, and it should be equal to 00 otherwise.

If there are multiple possible sequences leading to the optimal answer, print any of them.

输出恰好 ∣s∣|s| 个整数。如果 IA 应该翻转第 ii 个前缀(即从位置 11 到 ii 的子串),则第 ii 个整数应为 11;否则应为 00。

如果存在多个能得到最优答案的序列,输出其中任意一个即可。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页