CF C求调
  • 板块学术版
  • 楼主zhangxiao666
  • 当前回复9
  • 已保存回复9
  • 发布时间2024/1/28 01:00
  • 上次更新2024/1/28 10:09:39
查看原帖
CF C求调
742017
zhangxiao666楼主2024/1/28 01:00

都快调疯了,救救孩子吧qwq

#include <bits/stdc++.h>
using namespace std;
int n, k, m;
char s[1010];
int tot[27], be[27], en[27];

void work()
{
    memset(be, 0, sizeof(be));
    memset(en, 0, sizeof(en));
    memset(tot, 0, sizeof(tot));
    cin >> n >> k >> m;
    cin >> s + 1;
    for(int i = 1; i <= m; i++)
    {
        int x = s[i] - 'a' + 1;
        tot[x]++;
    }
    for(int i = 1; i <= k; i++)
    {
        if(tot[i] < n)
        {
            cout << "NO\n";
            char x = i + 'a' - 1;
            for(int j = 1; j <= n; j++)
            {
                cout << x;
            }
            cout << "\n";
            return;
        }
    }
    for(int i = 1; i <= m; i++)
    {
        int x = s[i] - 'a' + 1;
        if(!be[x]) be[x] = i;
        en[x] = i;
    }
    for(int i = 1; i <= k; i++)
    {
        for(int j = 1; j <= k; j++)
        {
            if(en[i] < be[j] && n > 1)
            {
                cout << "NO\n";
                char x = i + 'a' - 1;
                char y = j + 'a' - 1;
                for(int l = 1; l < n; l++) cout << y;
                cout << x;
                cout << "\n";
                return;
            }
        }
    }
    cout << "YES\n";
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T; cin >> T;
    while(T--) work();
    return 0;
}
2024/1/28 01:00
加载中...