QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549665#8829. Aibohphobiaucup-team4906#WA 0ms3856kbC++201.1kb2024-09-06 19:29:402024-09-06 19:29:40

Judging History

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

  • [2024-09-06 19:29:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-09-06 19:29:40]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)

using namespace std;

void sol() {
    string s; cin >> s;
    int n = s.size();
    s = " " + s;
    vector<int> cnt(26);
    int tot = 0;
    F(i, 1, n) {
        int x = s[i] - 'a';
        tot += ! cnt[x] ++;
    }
    // cout << tot << "!!\n";
    if(n == 1) {
        cout << "YES\n" << s[1] << "\n";
        return;
    }
    if(tot == 1) {
        cout << "NO\n";
        return;
    }
    int ok = 1;
    if(tot == 2) {
        ok = 0;
        F(i, 0, 25) if(cnt[i] == 1) ok = 1;
    }
    if(! ok) {
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
    F(i, 0, 25) if(cnt[i]) {
        cnt[i] --;
        cout << (char)(i + 'a');
    } 
    F(i, 1, n - tot) {
        F(j, 0, 25) if(cnt[j]) {
            cout << (char)(j + 'a');
            cnt[j] --;
            break;
        }
    }
    cout << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t; cin >> t;
    F(i, 1, t) sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

5
a
sos
abba
icpc
tenet

output:

YES
a
YES
oss
NO
YES
cipc
YES
entet

result:

ok Correct (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3856kb

input:

18
qnx
oooo
tvttj
zzzzz
pvlne
iijt
hjhjj
loo
hh
uq
mgvgv
ewwe
iii
kykk
o
mmumm
aetvv
xntl

output:

YES
nqx
NO
YES
jtvtt
NO
YES
elnpv
YES
ijti
NO
YES
loo
NO
YES
qu
YES
gmvgv
NO
NO
YES
kykk
YES
o
YES
mummm
YES
aetvv
YES
lntx

result:

wrong answer Some prefix is a palindrome (test case 14)