QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185798 | #2374. Cycle String? | Hanx16Msgr | WA | 1ms | 3908kb | C++14 | 1.0kb | 2023-09-22 16:57:14 | 2023-09-22 16:57:14 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i, a, b) for (int i = (a); i <= (b); ++i)
#define Rof(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
using i64 = long long;
constexpr int _N = 1e6 + 5;
string c;
deque<pair<int, int>> q;
int cnt[26];
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> c;
int n = c.length() / 2;
for (char t : c) ++cnt[t - 'a'];
int maxn = 0, p = 0;
For(i, 0, 25) if (cnt[i] > maxn) maxn = cnt[i], p = i;
string ans;
if (maxn >= n) {
int tmp = 0;
For(i, 0, 25) if (cnt[i] != maxn) tmp += cnt[i];
if (tmp < 2) return cout << "NO\n", 0;
vector<int> q;
For(i, 0, 25) if (i != p)
For(j, 1, cnt[i]) q.push_back(i);
tmp = 0;
For(i, 1, maxn) {
++tmp; ans += p + 'a';
if (tmp == n) {
ans += q.back() + 'a';
tmp = 0;
q.pop_back();
}
}
while (!q.empty()) ans += q.back() + 'a', q.pop_back();
} else {
For(i, 0, 25) For(j, 1, cnt[i])
ans += i + 'a';
}
cout << "YES\n" << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
cbbabcacbb
output:
YES bbbbbcccaa
result:
ok The contestant and jury found an answer
Test #2:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
aa
output:
NO
result:
ok Solution does not exist
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
afedbc
output:
YES abcdef
result:
ok The contestant and jury found an answer
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
cghfbdae
output:
YES abcdefgh
result:
ok The contestant and jury found an answer
Test #5:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
babcacca
output:
YES aaabbccc
result:
ok The contestant and jury found an answer
Test #6:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
hfjeacbdgi
output:
YES abcdefghij
result:
ok The contestant and jury found an answer
Test #7:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
fblcmcafgichjocodacanejmiaghclclmpnjcklkelhijghmgkhicdaafkgiaenjefkmmminihdfmiokjghdnohmddmgae
output:
YES aaaaaaaabcccccccccddddddeeeeefffffggggggghhhhhhhhiiiiiiiijjjjjjkkkkkklllllmmmmmmmmmmnnnnnoooop
result:
ok The contestant and jury found an answer
Test #8:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
babaccacbcacacbcabbcacacbbbbabccbcbaabbbabcbbcacaaccbbbaaacacaccaacabaabaaaabaabbccabcaaacccccabbcbacabccbacabacaccbbabccccabbacccbaacacaccbacababcaccaccacacbaaccbcccaaacaabbacbcbbcccaaaacbbcccccccccaabbcabcbcacbccaababcaaccccaccbcbacaacbaacbbaacbaacbacaaaacaaacbbbaccbabcababaccacacccbcbbcccaaaababa...
output:
YES aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb...
result:
ok The contestant and jury found an answer
Test #9:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
ccfaehbdffhadecdgacahfgbbbgcccfhfdbafbadddcgcfdafccdcafhaggeaghchcdegbfcecbhdhefdahddaeadacbachgdcchdcfdbefbbdcadegbefghceehabcaggahfahcgdchdbfhhcdefaadafcgdcfefdhebddhfahehedeefhcbdedafdaggbgggeadecgeefafafedcfgeehbhefhdfgdbebadeefdhhdedbgdfeehfchhfeffdfffghhehfbfegacbehdehcdaadhfhgdbhcaghcccgdcgdd...
output:
YES aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok The contestant and jury found an answer
Test #10:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
ifeehacdbg
output:
YES abcdeefghi
result:
ok The contestant and jury found an answer
Test #11:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
gwrffzdydmtyficvthjgseannpwxxkaqyrykfbziqszdirlwkqzsvwohmmcaudpyovcnfddsdvvytpdsal
output:
YES aaaabcccddddddddefffffgghhiiijkkkllmmmnnnoopppqqqrrrssssstttuvvvvvwwwwxxyyyyyyzzzz
result:
ok The contestant and jury found an answer
Test #12:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
gbmfhaeabeleiagcllhiiifmchighalckkghajaihiagmclibehjbaegdajebjhfbidahblcbemcdmmjbcdbhbdfldljmffgcbkdmacmjccmbjjmjccbaiiaffegbblbhehfaljdedhmkhldefdhgfgeagdglijediihclkcklcaefdmedkffabfcaliheaiaiagaegejmmddkkedbigkmdammkhemllbckieefclhglhgeabgfffkijjemekmkjggdjehmidbjjjhljdmjkeijaigiffkhfehkekglcaeje...
output:
YES aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...
result:
ok The contestant and jury found an answer
Test #13:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
pangkaeejgcohrfranglmibbnmldpriqndrjbhqcfdibgjlhedbghhiqcbhafrcpchhdjfakqnikdgpqcghcknnqrgpjjdhnjhbjhljdoorojmfbrrlljmimqfdrojmfldpdmclafhkmidqhalnrikcgmqgcnihorfnbojmfrrflqkmgbpqbieeffjbphrekocrmjjjopojmqahpeqpfkpmhpriarlmgoqmmjhdbpoaaiggpppgnhlfckcndmmklafdpnkgrkrgfhcgfhogghcmiobhgpjeenffmgbjjbdca...
output:
YES aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok The contestant and jury found an answer
Test #14:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
output:
NO
result:
ok Solution does not exist
Test #15:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
NO
result:
ok Solution does not exist
Test #16:
score: 0
Accepted
time: 1ms
memory: 3908kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
NO
result:
ok Solution does not exist
Test #17:
score: -100
Wrong Answer
time: 0ms
memory: 3780kb
input:
baabba
output:
NO
result:
wrong answer The contestant did not find a solution while jury did it