QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471107#8829. Aibohphobiaucup-team3519#WA 0ms3864kbC++201.3kb2024-07-10 18:06:252024-07-10 18:06:25

Judging History

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

  • [2024-07-10 18:06:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3864kb
  • [2024-07-10 18:06:25]
  • 提交

answer

#include <bits/stdc++.h>

void solve() {
    std::string s;
    std::cin >> s;

    std::vector<int> cnt(26);
    for (char c : s) {
        cnt[c - 'a'] += 1;
    }

    if (auto it = std::find(cnt.begin(), cnt.end(), 1); it != cnt.end()) {
        char c = 'a' + (it - cnt.begin());
        int p = std::find(s.begin(), s.end(), c) - s.begin();
        std::swap(s[0], s[p]);
        std::cout << "YES\n";
        std::cout << s << '\n';
        return;
    }

    int tot = 0;
    for (int i : cnt) {
        if (i) {
            ++tot;
        }
    }

    if (tot <= 2) {
        std::cout << "NO\n";
        return;
    }

    auto get = [&](std::set<int> exc) -> int {
        for (int i = 0; i < cnt.size(); ++i) {
            if (cnt[i] && exc.find('a' + i) == exc.end()) {
                --cnt[i];
                return 'a' + i;
            }
        }
        return -1;
    };

    char c = get({});
    get({});
    s[0] = s[2] = c;
    s[1] = get({s[0]});
    s[2] = get({s[0], s[1]});
    for (int i = 3; i < s.size(); ++i) {
        s[i] = get({});
    }
    std::cout << "YES\n";
    std::cout << s << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }
}

详细

Test #1:

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

input:

5
a
sos
abba
icpc
tenet

output:

YES
a
YES
oss
NO
YES
icpc
YES
netet

result:

ok Correct (5 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3524kb

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
jvttt
NO
YES
evlnp
YES
jiit
NO
YES
loo
NO
YES
qu
YES
mgvgv
NO
NO
YES
ykkk
YES
o
YES
ummmm
YES
aetvv
YES
lntx

result:

ok Correct (18 test cases)

Test #3:

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

input:

138
gcseqpht
brrrzsrerr
ree
lgryyyh
wbxkwwwwx
hsihaga
kvvslzgv
dssd
qhrqqqrqyh
dfffffsfgf
ssuzuuzzs
rrwnyrcdnb
ealelecu
ccfwwwccwc
emeieme
xeexeswes
ymkkkkpkk
eimderoz
lflllh
lluylcll
rquqrqu
mllmllll
cscscc
ssssssssss
cn
llljlzlzj
h
kbbxahczit
yxrrrrxlkr
uikiakika
tntnnqntw
sjhxyfsy
fcyyyf
dbvbvdbw...

output:

YES
cgseqpht
YES
brrrzsrerr
YES
ree
YES
glryyyh
YES
bwxkwwwwx
YES
gsihaha
YES
gvvslzkv
NO
YES
yhrqqqrqqh
YES
dfffffsfgf
YES
suzsuuzz

result:

wrong answer Not a permutation (test case 11)