QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471103#8829. Aibohphobiaucup-team3519#WA 1ms3628kbC++201.3kb2024-07-10 18:04:522024-07-10 18:04:52

Judging History

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

  • [2024-07-10 18:04:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3628kb
  • [2024-07-10 18:04:52]
  • 提交

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({});
    }
}

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: 3628kb

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: 3592kb

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: 1ms
memory: 3504kb

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
brwnyrcdnr
YES
aelelecu
YES
fccwwwccwc
YES
imeeeme
YES
weexesxes
YES
mykkkkpkk
YES
dimeeroz
YES
fllllh
YES
cluyllll
NO
NO
NO
YES
cn
YES
h
YES
abbxkhczit
YES
kxrrrrxlyr
YES
uiki...

result:

wrong answer Not a permutation (test case 11)