CF1450G.Communism

NOI/NOI+/CTSC

通过率:0%

时间限制:1.50s

内存限制:32MB

AC君温馨提醒

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

题目描述

Please pay attention to the unusual memory limit in this problem.

In a parallel universe, Satan is called "Trygub". For that reason, the letters of his namesake were deleted from the alphabet in ancient times.

The government has nn workers standing in a row and numbered with integers from 11 to nn from left to right. Their job categories can be represented as a string ss of length nn, where the character sis_i represents the job category of the ii-th worker.

A new law will be approved to increase the equality between the workers. The government decided to make everyone have the same job category by performing the following operation any number of times (possibly zero).

There is a fixed rational parameter k=abk=\frac ab describing how easy it is to convince the public, and it will be used to determine the success of an operation.

In an operation, the government first selects a job category xx with at least one worker at the current moment. Suppose i1,…,imi_1,\ldots, i_m (i1<…<imi_1 \lt \ldots \lt i_m) are the positions of all the workers with job category xx. If k⋅(im−i1+1)≤mk\cdot (i_m-i_1+1)\le m, the government is able to choose any job category yy with at least one worker at the current moment and change the job category of all workers with job category xx to job category yy.

If it is possible to make all workers have job category xx, we say that xx is obtainable. Can you tell the government the set of obtainable job categories?

请注意本题不同寻常的内存限制。

在某个平行宇宙中,撒旦被称为“Trygub”。正因如此,其名字所含的字母在远古时代便被从字母表中删除了。

政府有 nn 名工人排成一列,从左到右依次编号为 11 到 nn。他们的职业类别可用一个长度为 nn 的字符串 ss 表示,其中字符 sis_i 表示第 ii 名工人的职业类别。

一项旨在提升工人间平等性的新法律即将获得通过。政府决定通过执行以下操作(可执行任意多次,包括零次)使得所有工人的职业类别完全相同。

存在一个固定的有理数参数 k=abk=\frac ab,用于刻画说服公众的难易程度,并将据此判定每次操作是否成功。

一次操作的具体流程如下:政府首先选择一种当前至少拥有一名工人的职业类别 xx。设所有职业为 xx 的工人位置为 i1,…,imi_1,\ldots, i_m(满足 i1<…<imi_1 \lt \ldots \lt i_m)。若满足不等式 k⋅(im−i1+1)≤mk\cdot (i_m-i_1+1)\le m,则政府便可任选一种当前至少拥有一名工人的职业类别 yy,并将所有职业为 xx 的工人的职业类别全部更改为 yy。

若能通过若干次操作使得所有工人的职业类别均为 xx,则称 xx 是可达成的。你能告诉政府所有可达成的职业类别构成的集合吗?

输入格式

The first line contains three integers n,a,bn, a, b (1≤n≤50001 \le n \le 5000, 1≤a≤b≤1051\le a\le b\le 10^5) — the number of workers and the numerator and denominator of the parameter kk, respectively.

The second line contains a string ss of length nn, consisting of lowercase English characters — the job categories of each worker. The characters 't', 'r', 'y', 'g', 'u', and 'b' do not appear in the string ss.

第一行包含三个整数 n,a,bn, a, b(1≤n≤50001 \le n \le 5000,1≤a≤b≤1051\le a\le b\le 10^5),分别表示工人的数量以及参数 kk 的分子和分母。

第二行包含一个长度为 nn 的字符串 ss,由小写英文字母组成——表示每位工人所属的工作类别。字符串 ss 中不出现字符 't'、'r'、'y'、'g'、'u' 和 'b'。

输出格式

Print an integer cc equal to the number of obtainable job categories followed by cc space-separated characters — the obtainable job categories sorted in the lexicographical order.

输出一个整数 cc,表示可获得的工作类别数量;然后输出 cc 个用空格分隔的字符——即可获得的工作类别,按字典序排序。

输入输出样例

  • 输入#1

    7 1 2
    comicom

    输出#1

    3 c m o

说明/提示

The first operation must select the job category 'i' because all other job categories cannot satisfy the condition, therefore 'i' is not obtainable.

Below is showed how to obtain 'c', 'm', and 'o'. The square brackets denote the segment containing all workers of the selected category, the red color denotes this category and the blue color denotes the new category after the change.

  • Get 'c':
    1. (com[i]com→com[o]com\texttt{com}\color{red}{\texttt{[i]}}\texttt{com} \rightarrow \texttt{com}\color{#1E90FF}{\texttt{[o]}}\texttt{com})
    2. (c[omoco]m→c[mmmcm]m\texttt{c}\color{red}{\texttt{[o}}\texttt{m}\color{red}{\texttt{o}}\texttt{c}\color{red}{\texttt{o]}}\texttt{m} \rightarrow \texttt{c}\color{#1E90FF}{\texttt{[m}}\texttt{m}\color{#1E90FF}{\texttt{m}}\texttt{c}\color{#1E90FF}{\texttt{m]}}\texttt{m})
    3. (c[mmmcmm]→c[cccccc]\texttt{c}\color{red}{\texttt{[mmm}}\texttt{c}\color{red}{\texttt{mm]}} \rightarrow \texttt{c}\color{#1E90FF}{\texttt{[ccc}}\texttt{c}\color{#1E90FF}{\texttt{cc]}})
  • Get 'm':
    1. (com[i]com→com[o]com\texttt{com}\color{red}{\texttt{[i]}}\texttt{com} \rightarrow \texttt{com}\color{#1E90FF}{\texttt{[o]}}\texttt{com})
    2. (c[omoco]m→c[cmccc]m\texttt{c}\color{red}{\texttt{[o}}\texttt{m}\color{red}{\texttt{o}}\texttt{c}\color{red}{\texttt{o]}}\texttt{m} \rightarrow \texttt{c}\color{#1E90FF}{\texttt{[c}}\texttt{m}\color{#1E90FF}{\texttt{c}}\texttt{c}\color{#1E90FF}{\texttt{c]}}\texttt{m})
    3. ([ccmccc]m→[mmmmmm]m\color{red}{\texttt{[cc}}\texttt{m}\color{red}{\texttt{ccc]}}\texttt{m} \rightarrow \color{#1E90FF}{\texttt{[mm}}\texttt{m}\color{#1E90FF}{\texttt{mmm]}}\texttt{m})
  • Get 'o':
    1. (com[i]com→com[c]com\texttt{com}\color{red}{\texttt{[i]}}\texttt{com} \rightarrow \texttt{com}\color{#1E90FF}{\texttt{[c]}}\texttt{com})
    2. ([comcc]om→[mommm]om\color{red}{\texttt{[c}}\texttt{om}\color{red}{\texttt{cc]}}\texttt{om} \rightarrow \color{#1E90FF}{\texttt{[m}}\texttt{om}\color{#1E90FF}{\texttt{mm]}}\texttt{om})
    3. ([mommmom]→[ooooooo]\color{red}{\texttt{[m}}\texttt{o}\color{red}{\texttt{mmm}}\texttt{o}\color{red}{\texttt{m]}} \rightarrow \color{#1E90FF}{\texttt{[o}}\texttt{o}\color{#1E90FF}{\texttt{ooo}}\texttt{o}\color{#1E90FF}{\texttt{o]}})

第一次操作必须选择工作类别 “i”,因为其他所有工作类别均无法满足条件,因此 “i” 是不可获得的。

以下是获得 “c”、“m” 和 “o” 的过程。方括号表示所选类别的所有工人所在的连续段;红色表示该被选中的类别,蓝色表示变换后的新类别。

  • 获得 “c”:
    1. (com[i]com→com[o]com\texttt{com}\color{red}{\texttt{[i]}}\texttt{com} \rightarrow \texttt{com}\color{#1E90FF}{\texttt{[o]}}\texttt{com})
    2. (c[omoco]m→c[mmmcm]m\texttt{c}\color{red}{\texttt{[o}}\texttt{m}\color{red}{\texttt{o}}\texttt{c}\color{red}{\texttt{o]}}\texttt{m} \rightarrow \texttt{c}\color{#1E90FF}{\texttt{[m}}\texttt{m}\color{#1E90FF}{\texttt{m}}\texttt{c}\color{#1E90FF}{\texttt{m]}}\texttt{m})
    3. (c[mmmcmm]→c[cccccc]\texttt{c}\color{red}{\texttt{[mmm}}\texttt{c}\color{red}{\texttt{mm]}} \rightarrow \texttt{c}\color{#1E90FF}{\texttt{[ccc}}\texttt{c}\color{#1E90FF}{\texttt{cc]}})
  • 获得 “m”:
    1. (com[i]com→com[o]com\texttt{com}\color{red}{\texttt{[i]}}\texttt{com} \rightarrow \texttt{com}\color{#1E90FF}{\texttt{[o]}}\texttt{com})
    2. (c[omoco]m→c[cmccc]m\texttt{c}\color{red}{\texttt{[o}}\texttt{m}\color{red}{\texttt{o}}\texttt{c}\color{red}{\texttt{o]}}\texttt{m} \rightarrow \texttt{c}\color{#1E90FF}{\texttt{[c}}\texttt{m}\color{#1E90FF}{\texttt{c}}\texttt{c}\color{#1E90FF}{\texttt{c]}}\texttt{m})
    3. ([ccmccc]m→[mmmmmm]m\color{red}{\texttt{[cc}}\texttt{m}\color{red}{\texttt{ccc]}}\texttt{m} \rightarrow \color{#1E90FF}{\texttt{[mm}}\texttt{m}\color{#1E90FF}{\texttt{mmm]}}\texttt{m})
  • 获得 “o”:
    1. (com[i]com→com[c]com\texttt{com}\color{red}{\texttt{[i]}}\texttt{com} \rightarrow \texttt{com}\color{#1E90FF}{\texttt{[c]}}\texttt{com})
    2. ([comcc]om→[mommm]om\color{red}{\texttt{[c}}\texttt{om}\color{red}{\texttt{cc]}}\texttt{om} \rightarrow \color{#1E90FF}{\texttt{[m}}\texttt{om}\color{#1E90FF}{\texttt{mm]}}\texttt{om})
    3. ([mommmom]→[ooooooo]\color{red}{\texttt{[m}}\texttt{o}\color{red}{\texttt{mmm}}\texttt{o}\color{red}{\texttt{m]}} \rightarrow \color{#1E90FF}{\texttt{[o}}\texttt{o}\color{#1E90FF}{\texttt{ooo}}\texttt{o}\color{#1E90FF}{\texttt{o]}})

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

首页