QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#458280#8829. Aibohphobiaucup-team3608#TL 0ms0kbC++171.3kb2024-06-29 16:30:552024-06-29 16:30:57

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 16:30:57]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-06-29 16:30:55]
  • 提交

answer

#include"bits/stdc++.h"

using lint = int64_t;

using namespace std;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int t; cin>>t;
    while(t--){
        string s; cin>>s;
        const int n = s.size();
        if(n == 1){
            cout<<"YES\n";
            cout<<s<<"\n";
            continue;
        }
        vector<int> cnt(26);
        for(char c: s)
            cnt[c-'a']++;
        int small = 0;
        for(int i = 0; i < 26; i++){
            if((cnt[small] == 0 && cnt[i] != 0) || cnt[i] < cnt[small])
                small = i;
        }
        string ans;
        ans += 'a' + small;
        cnt[small] --;
        for(int i = 0; i < 26; i++){
            if(i == small) continue;
            while(cnt[i] != 0){
                ans += char('a' + i);
                cnt[i]--;
            }
        }
        if(cnt[small]){
            ans += 'a' + small;
            cnt[small] --;
            string t = ans;
            reverse(t.begin(), t.end());
            if(ans == t){
                cout<< "NO\n";
                continue;
            }
        }
        while(cnt[small] != 0){
            ans += char('a' + small);
            cnt[small]--;
        }
        cout<< "YES\n";
        cout<<ans<<"\n";

    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

5
a
sos
abba
icpc
tenet

output:


result: