QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#471103 | #8829. Aibohphobia | ucup-team3519# | WA | 1ms | 3628kb | C++20 | 1.3kb | 2024-07-10 18:04:52 | 2024-07-10 18:04:52 |
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({});
}
}
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)