QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#471107 | #8829. Aibohphobia | ucup-team3519# | WA | 0ms | 3864kb | C++20 | 1.3kb | 2024-07-10 18:06:25 | 2024-07-10 18:06:25 |
Judging History
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)