CodeForces - 771B Bear and Different Names (思维 + 构造)

Bear and Different Names

In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).

A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't.

You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of kconsecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not.

You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO".

  • The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise).
  • The string s2 describes a group of soldiers 2 through k + 1.
  • And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n.

Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example.

Find and print any solution. It can be proved that there always exists at least one solution.

Input

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively.

The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise.

Output

Find any solution satisfying all given conditions. In one line print nspace-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10.

If there are multiple valid solutions, print any of them.

Examples

Input

8 3
NO NO YES YES YES NO

Output

Adam Bob Bob Cpqepqwer Limak Adam Bob Adam

Input

9 8
YES NO

Output

R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc

Input

3 2
NO NO

Output

Na Na Na

Note

In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:

  • First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1is "NO".
  • Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO".
  • Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES".
  • ...,
  • Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".

题意:输入两个整数 n 和 k, n 代表有 n 个名字, k 代表 k 个名字为一组。 之后会输入 n - k + 1 个 YES 或者 NO,YES 表示 这 k 个名字中没有重名, NO 代表有重名。 你需要构造这 n 个名字,满足题目中所有的YES 和 NO,对于每个名字 以大写字母开头,可以是一个字母,也可以是多个字母;

思路:这个题如果想到了构造的思路,这个题不难。 对于第 i 个YES 或者 NO,  它对应的一个名字就是 第 i 个,所以我们从后往前构造, 如果是 NO, 这第 i 个的名字就和第 i + k - 1 个名字是相同的,反之   继续使用下一个名字。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    string name[60];
    for(int i = 0;i < 26;i ++) name[i] = i + 'A';
    for(int i = 26;i < 52;i ++) name[i] = name[i - 26] + 'a';
    while(~scanf("%d%d",&n,&k)){
        string yeno[60];
        for(int i = 1;i <= n - k + 1;i ++) cin >> yeno[i];
        int p = 0;
        string ans[60];
        for(int i = n;i >= n - k + 2;i --)
            ans[i] = name[p ++];

        for(int i = n - k + 1;i >= 1;i --){
            if(yeno[i] == "NO"){
                ans[i] = ans[i + k - 1];
            }
            else if(yeno[i] == "YES"){
                ans[i] = name[p ++];
            }
        }
        for(int i = 1;i <= n;i ++)
            cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/no_O_ac/article/details/82118624