QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#457530 | #8829. Aibohphobia | ucup-team1004# | WA | 1ms | 3624kb | C++14 | 845b | 2024-06-29 13:11:48 | 2024-06-29 13:14:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int t[26],n,T;
char str[1000010];
bool chk1()
{
for(int i=0;i<26;i++)
if(t[i]==1)
{
puts("YES");
putchar(i+'a'),t[i]=0;
for(int j=0;j<26;j++)
while(t[j]--) putchar(j+'a');
puts("");
return 1;
}
return 0;
}
bool chk2()
{
int cnt=0;
for(int i=0;i<26;i++) cnt+=(t[i]>0);
return cnt==2;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
n=strlen(str);
for(int i=0;i<26;i++) t[i]=0;
for(int i=0;i<n;i++) t[str[i]-'a']++;
if(chk1()) continue;
else if(chk2()) {puts("NO");continue;}
for(int i=0;i<26;i++)
if(t[i])
{
puts("YES");
putchar(i+'a'),t[i]--;
for(int j=0;j<26;j++)
if(j!=i) while(t[j]--) putchar(j+'a');
while(t[i]--) putchar(i+'a');
break;
}
puts("");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
input:
5 a sos abba icpc tenet
output:
YES a YES oss NO YES iccp YES neett
result:
ok Correct (5 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3616kb
input:
18 qnx oooo tvttj zzzzz pvlne iijt hjhjj loo hh uq mgvgv ewwe iii kykk o mmumm aetvv xntl
output:
YES nqx YES oooo YES jtttv YES zzzzz YES elnpv YES jiit NO YES loo YES hh YES qu YES mggvv NO YES iii YES ykkk YES o YES ummmm YES aetvv YES lntx
result:
wrong answer Some prefix is a palindrome (test case 2)