QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463356 | #8829. Aibohphobia | May_27th | TL | 71ms | 3884kb | C++20 | 1.4kb | 2024-07-04 18:59:15 | 2024-07-04 18:59:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define i128 __int128
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
void Solve(void) {
string S; cin >> S;
vector<int> cnt(26, 0), cnt1(26, 0);
vector<int> cs;
for (int i = 0; i < (int)S.size(); i ++) {
cnt[S[i] - 'a'] ++;
cnt1[S[i] - 'a'] ++;
cs.pb(S[i] - 'a');
}
sort(all(cs)); cs.erase(unique(all(cs)), cs.end());
int p = 0, p1 = 1, sz = cs.size();
string ans = "", ans1 = "";
for (int i = 0; i < (int)S.size(); i ++) {
while (cnt[cs[p]] == 0) p = (p + 1) % sz;
ans = ans + char(cs[p] + 'a');
cnt[cs[p]] --;
p = (p + 1) % sz;
while (cnt1[cs[p1]] == 0) p1 = (p1 + 1) % sz;
ans1 = ans1 + char(cs[p1] + 'a');
cnt1[cs[p1]] --;
p1 = (p1 + 1) % sz;
}
bool flag = true, flag1 = true;
if ((int)ans.size() > 1 && ans[1] == ans[0] || (int)ans.size() > 2 && ans[2] == ans[0]) flag = false;
if ((int)ans1.size() > 1 && ans1[1] == ans1[0] || (int)ans1.size() > 2 && ans1[2] == ans1[0]) flag1 = false;
if (!flag && !flag1) {
cout << "NO" << "\n";
return;
}
cout << "YES" << "\n";
if (flag) cout << ans << "\n";
else if (flag1) cout << ans1 << "\n";
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(10);
int Tests = 1; cin >> Tests;
while (Tests --) {
Solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
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: 0
Accepted
time: 0ms
memory: 3684kb
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 ykkk YES o YES ummmm YES aetvv YES lntx
result:
ok Correct (18 test cases)
Test #3:
score: 0
Accepted
time: 0ms
memory: 3644kb
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 ceghpqst YES berszrrrrr YES ree YES ghlryyy YES bkwxwxwww YES aghisah YES gklsvzvv NO YES hqryhqrqqq YES dfgsffffff YES suzsuzsuz YES bcdnrwynrr YES aceluele YES cfwcwcwcwc YES eimemee YES eswxesxee YES kmpykkkkk YES deimorze YES fhllll YES cluyllll YES qruqruq NO NO NO YES cn YES jlzjlzlll YES ...
result:
ok Correct (138 test cases)
Test #4:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
683 ufvvflppuvfu ccgchccndvvtqcu dqgqdddrgddjid iiiiiiiiiiimiin dqsiejxqqqq kkkjzkkzkkvvkkk aaeamagwzwagmni bgddgdbbggdgb xebbzbqrrx tyxkqsyyclhyx bjpdrrrrrrjrv qzzqzzzqqq ykgaykqyqqk iefeeetaeeee qqbabbfbslxfh ovvczvcdcvecb ieiiiaiqiiibii hxeeeexeexxxxh jxxxjxjrjjjx jjzjjrzgqnjyj rqqtzzptqopq wbsyv...
output:
YES flpuvfpuvfuv YES cdghnqtuvcvcccc YES dgijqrdgqddddd YES imniiiiiiiiiiii YES deijqsxqqqq YES jkvzkvzkkkkkkkk YES aegimnwzagmwaaa YES bdgbdgbdgbdgg YES beqrxzbrxb YES chklqstxyxyyy YES bdjprvjrrrrrr NO YES agkqykqykqy YES aefiteeeeeee YES abfhlqsxbfqbb YES bcdeovzcvcvcv YES abeiqiiiiiiiii YES ehxe...
result:
ok Correct (683 test cases)
Test #5:
score: 0
Accepted
time: 4ms
memory: 3544kb
input:
2713 ahrfzkzqahzahbqahzzu vwwwdpdsopmwmdmss zhkzhzjefkvnjfbxxbk oawqeraqvqoqqg eeeeedsxddeehzeehzee afrzcqrhdqikqcvqcakj xqkkkzqquqqkqqkdd urtrttjuruttutruutut mktgalyydawhgtcka qjhjjxxqhhqxqx fkfzfkffkfkkfffkkfz byyyqbbboboyqqoobb eyeyylrleeylerllrly ggfgzqgyqvqlehnq rrsjrrjrrjjjjrrrzrr qyqqyycrqrr...
output:
YES abfhkqruzahqzahzahzz YES dmopsvwdmpswdmsww YES befhjknvxzbfhjkxzkz YES aegoqrvwaoqqqq YES dehsxzdehzdeeeeeeeee YES acdfhijkqrvzackqrcqq YES dkquxzdkqkqkqkqqq YES jrturturturtutututut YES acdghklmtwyagktya YES hjqxhjqxhjqxqx YES fkzfkzfkfkfkfkfkfff YES boqyboqyboqyboybbb YES elryelryelryelyelyl Y...
result:
ok Correct (2713 test cases)
Test #6:
score: 0
Accepted
time: 71ms
memory: 3856kb
input:
35444 vvgmvmmhtmgmmhvfhhhmhmqmqhmhhvf aiiaaaaipaiapsspcppaaappppypapa qgprgwugggggiqargigggugefgarg ssikskkmiisksqsssssssn dtvmryhhtikrrhmmhmmymrmimbvpvv cpbpprllqzletlllplugkxf sbpkbkbsptsbkkkbtbtsktkb ngvnnvnvgcgcnvnngnnnnvgn mhhyltymyjhynhhyymtyuuuyydjyyys vlbkkgmtekutxaltkltttkkcakttlkl njemezmg...
output:
YES fghmqtvfghmqvhmvhmvhmvhmhmhmhmm YES acipsyaipsaipaipapapapapapapapa YES aefgipqruwagiqrugrggggggggggg YES ikmnqsiksiksksssssssss YES bdhikmprtvyhimrtvyhmrvhmrvmmmm YES bcefgklpqrtuxzlplplplll YES bkpstbkpstbkstbkstbkbkbk YES cgnvcgnvgnvgnvgnvnnnnnnn YES dhjlmnstuyhjmtuyhmuyhyhyyyyyyyy YES abcegk...
result:
ok Correct (35444 test cases)
Test #7:
score: -100
Time Limit Exceeded
input:
1 lllvrvrqtekpyfwztplrzmkfmlvllvjmzffllrmemmyjmlllwbiruatutvvumfttuemtjvmfvmjktlfzwmllfitqtvjtqftvergkqtebzjmwtvfjklklgjjevuuqrjzltrutklzytzvjyjuzlvjlivilvwtztijfrmvfkmfkiuxrtpftibbrlzvltbljbjtiqlzzjtyvljklvluutzqjvltenvtjlmtjyejvvlverflbvmkvjfwtlvrvmpbtpllvpbklqkulezkmrmltljvtklvitqelmvqvvfqfofkfyu...