QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#781922 | #8234. Period of a String | louhao088 | WA | 63ms | 47424kb | C++23 | 2.2kb | 2024-11-25 18:00:48 | 2024-11-25 18:00:53 |
Judging History
answer
#pragma GCC Optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lowbit(i) (i&(-i))
const int mod=1e9+7,maxn=5e6+5,M=1e5+5;
inline int read(){
char ch=getchar();int x=0;bool f=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
int T,n,m,x;
int sz[maxn],st[maxn],g[maxn];
int top,ch[M][27],ans[maxn][27];
int sum[27];
vector<int>a[maxn];
char s[maxn];
void print(){
puts("YES");
for(int i=1;i<=n;i++){
for(int j=0;j<sz[i];j++)
putchar(s[a[i][j]]);
puts("");
}
}
int get(int x){
int l=0,r=top,res=0;
while(l<=r){
int mid=(l+r)/2;
if(sz[st[mid]]<=x)res=mid,l=mid+1;
else r=mid-1;
}return st[res];
}
void solve(){
n=read();top=0;
scanf("%s",s);
//if(T==53){cout<<n<<endl;cout<<s<<endl;}
sz[1]=strlen(s);a[1].resize(sz[1]);
for(int i=0;i<sz[1];i++){
ch[1][s[i]-'a']++;
a[1][i]=i;
}
g[sz[1]]=1;
for(int i=0;i<26;i++)ans[sz[1]][i]=ch[1][i];
st[++top]=1;bool flag=0;
for(int i=2;i<=n;i++){
scanf("%s",s);
sz[i]=strlen(s);
a[i].resize(sz[i]);
vector<int>tmp;
tmp.clear();
tmp.resize(27);
for(int j=0;j<sz[i];j++){
a[i][j]=a[i-1][j%sz[i-1]];
ch[i][s[j]-'a']++;
tmp[s[j]-'a']++;
}
int t=sz[i],z=get(t);
while(z){
int p=t/sz[z];
t=t%sz[z];
for(int j=0;j<26;j++){
tmp[j]=tmp[j]-ch[z][j]*p;
if(tmp[j]<0){flag=1;break;}
}z=get(t);
}
if(!g[t]){
g[t]=1;
for(int j=0;j<26;j++){
ans[t][j]=tmp[j];
if(tmp[j]>ch[1][j]){flag=1;break;}
}
}
else {
for(int j=0;j<26;j++)if(ans[t][j]!=tmp[j]){flag=1;break;}
}
while(top&&sz[st[top]]>=sz[i])top--;
st[++top]=i;
}
for(int i=0;i<26;i++)sum[i]=0;
int tot=0;
for(int i=1;i<=sz[1];i++){
if(!g[i])continue;g[i]=0;
for(int j=0;j<26;j++)if(sum[j]>ans[i][j])flag=1;
for(int j=0;j<26;j++)if(sum[j]<ans[i][j]){
for(int k=sum[j]+1;k<=ans[i][j];k++)s[tot++]=j+'a';
sum[j]=ans[i][j];
}
//cout<<tot<<endl;
for(int j=0;j<26;j++)ans[i][j]=0;
}
if(flag)puts("NO");
else print();
for(int i=1;i<=n;i++){
for(int j=0;j<=26;j++)ch[i][j]=0;
a[i].clear();
}
}
signed main(){
T=read();
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 13900kb
input:
4 2 abc abcd 4 bbcaa cabb acabbbb a 3 ab aab bbaaaaab 3 ab aab bbaaaaaa
output:
NO YES abbca abbc abbcabb a YES ab aba abaabaab NO
result:
ok ok (4 test cases)
Test #2:
score: 0
Accepted
time: 5ms
memory: 13852kb
input:
5 1 ccecddbdbbcbbaded 3 cd d d 1 dcedec 2 dcec cce 8 a e a c cc cccccccc c b
output:
YES abbbbbccccdddddee YES dc d d YES ccddee YES cced cce NO
result:
ok ok (5 test cases)
Test #3:
score: 0
Accepted
time: 50ms
memory: 20356kb
input:
100 147 ababbbaaaaaababbbbbaabaabbbbaaaababbbbababaabbbbaaabbabaaaaaabbbbaabbaaaaaababbbaabbabbaaabbbaabbbabaabbbbaabaabbaa aaaaabbbbababababbbaaaaaabaaaaabbaabaabaaababbabbabbabbaabbaaabbaabbaabaababaaabbababbbbbaabaaaaabbbbaabbbbbbaaabbbbabaababbbbb ababbabaababbbbaabbbbaaabbabaabbaaaababbbabbaaab...
output:
NO YES baaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb ba bababababababababababababababababababababab bababababababababababababababab babababab bababababbababababb bababababbabab baba bababababababab b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb b bbbbbbbbbbbbbb bbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbb bbbbbbbb...
result:
ok ok (100 test cases)
Test #4:
score: 0
Accepted
time: 46ms
memory: 17732kb
input:
100 326 decadadcaaacaaeecaddaeadeadc aaadedcaaeaaeddddaeaceaddaaaaecccaaeadeaaedaccdddcdddaaaadddacceaaadcadaeeeadeeadccdaacadaaecaedadcaaaecdaddaeaaaeccdedaceaaaacdddcecdcdacddccecaaaeaeedacaeaadaaacdadedae acaecaaaedcdaceaaddddaaeaddccdaeaadaeedaecdacaadeeaadeceadacdadaccdaaedaddccaceea ddccacdcea...
output:
NO YES ebccdeabb ebccde ebccd ebccdebccdebccdebccd ebccde e eeeeeeeeeeeeeeeee eeeeeeeeeeee eeeeeee eeeeeeeeeeeee eee eeeeeeeeeeeeeeee eeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee eeeeeeeeeee eeeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeee eeeeeeeeeeee eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eeeeeeeeee eee...
result:
ok ok (100 test cases)
Test #5:
score: 0
Accepted
time: 48ms
memory: 20312kb
input:
100 1114 mmiceajjcjdemdhf c ccccccc cccccc cccccccccccccccccccccccccccccccccccccccc ccccccccc ccccccccc ccccccccccccccc ccccccccccccccccccccccccc cccccccccc ccc ccccccccccc ccccccccccccccccccccccccccccccc ccccccccc cccccc ccccccccccccccccccccccc ccccccccccccc ccc ccccccccccc ccccccccc cccccccccccccc...
output:
NO NO YES acgbacmikmfaaddehiibfjkacaaaaaabbbbbbcccccccccdddddeeeeeeeeeeeeefffffffgggggggghhhhhhiiiiiiiiijjjjjjjjkkkkkkklllllllmmmmm acgbacmikmfaaddehiibfjkac acgbacmikmfaaddehiibfjkacacgbacmikmfaaddehiibfjkacacgbacmikmfaaddehiibfjkacacgbacm acgbacmikmfaaddehiibfjkacacgbacmikmfaaddehiibfjkacacgbacmik...
result:
ok ok (100 test cases)
Test #6:
score: 0
Accepted
time: 37ms
memory: 17856kb
input:
100 512 tecvaycvrbprboqldxlzjmlbfxaseuomtjxenfyoxkmjqkifjpacqytpxmbxleryljfxeoghwfhcnhvimgkvdwjcwatlppmwbbygdbiyzvlrfqjmdnuioulrgmwfkutwgavesanvdzbypveznnvrddujscaekxauxwi nqmlelkfqrvjbwdlvtbzxkd kbdqfbqxqqvmkllqltebqmlrnxvxflkzedrmbwknzltfbllqllbwllwqrvkzmrdqlldvnfbkqxbdkewxrzbbndvfqrnfklllxxkvqkjf...
output:
YES vzxjrblkeqmvnftqbdkdllwaaaaaaaabbbbbbccccccdddddeeeeeeeffffffggggghhhiiiiijjjjjjjkkklllllmmmmmmmnnnnnoooooppppppqqrrrrrsssttttuuuuuuvvvvvvvwwwwwwxxxxxxxxyyyyyyyzzz vzxjrblkeqmvnftqbdkdllw vzxjrblkeqmvnftqbdkdllwvzxjrblkeqmvnftqbdkdllwvzxjrblkeqmvnftqbdkdllwvzxjrblkeqmvnftqbdkdllwvzxjrblkeqmvnftq...
result:
ok ok (100 test cases)
Test #7:
score: 0
Accepted
time: 47ms
memory: 19088kb
input:
1000 379 hdiyyp ihy hyhyiih hiyh iyhhihihhyhy yhihhyyihhih h hhh h h hhhhh hhhh hhhhhhhhh hhhhhhhhhhhhh hhhhhhhhhhhhhhhhh hh hhh hhhhh hhhhhhhh hhhhhhhhhhhhhhhh hhh hhhhhhhh hhhhhhhhh h hhh hhhhhh hhhh hh hhhhhhhhhh hhhhhhh hh hhhhh hhhhhh hhhh h hh hh hh hh hhhhhhhhhhhhh hhhhh hhhh hhhhhh hhhh h hh...
output:
YES hiydpy hiy hiyhiyh hiyh hiyhhiyhhiyh hiyhhiyhhiyh h hhh h h hhhhh hhhh hhhhhhhhh hhhhhhhhhhhhh hhhhhhhhhhhhhhhhh hh hhh hhhhh hhhhhhhh hhhhhhhhhhhhhhhh hhh hhhhhhhh hhhhhhhhh h hhh hhhhhh hhhh hh hhhhhhhhhh hhhhhhh hh hhhhh hhhhhh hhhh h hh hh hh hh hhhhhhhhhhhhh hhhhh hhhh hhhhhh hhhh h hhhhhh ...
result:
ok ok (1000 test cases)
Test #8:
score: 0
Accepted
time: 55ms
memory: 14124kb
input:
10000 21 uiutbnjregblkwbpztgdbmahtlhe dtulrltbnbtlbggtwmteiwzbejzdlzbtbutiapwhnurumbnutkekbjehanphbhrn unt tnnntktntttttnttutnuuuuuunntuuuntununutnntuttunuutttntnuntnuuntuttunnuututuntuttntnunntuntnnuuttutunuunnunuutnuuutnutnutnnntntntunnttntuuttnnuunnnnuuutntn uttnnnntuuuutututtnttuutuuttnnnnntunnu...
output:
NO YES y y y y y YES kabhlmmszgklamrcgo kabhlmmszgklamrcgokabhlmmszgkl kabhlmmszgklamrcgokabhlmmszgklkabhlmmszgklamrcgokabhlmmszgklkabhlmmsz kabhlmmszgklamrcgokabhlmmszgklkabhlmmszgklamrcgokabhlmmszgklkabhlmmszkabhlmmszgklamrcgokabhlmmszgklkabhlmmszgklamrcgokabhlmmszgklkabhlmmszkabhlmmszgklamrcgokab...
result:
ok ok (10000 test cases)
Test #9:
score: 0
Accepted
time: 60ms
memory: 30240kb
input:
10 16467 aldyra ylaaaddrraldyaaalaaadrydlyyaryrrl draya yaaaadddarayrayraayyyraradddr yyraayrdardraaadraaydadyya dray ay yaayayaayyayaaaayyyaayayyyayayyayyaaayayya ayayayyyaayyyyaayayayaa aaayyaayyaaayyayyyyyyaayayaay yyyyyayyayyyayyayyaayayayayyayayayaaaaaayayaaaaay yaayay ayaayayyyayyyayaayaayyyay...
output:
NO YES nbjklmphbnoqrswyddehijllllqqsswcdiinooqwbabcginoppqrrrsuwxzccijnsuvx nbjklmphbnoqrswyddehijllllqqsswcdiinooqwbabcginoppqrrrsuwxz nbjklmphbnoqrswyddehijllllqqsswcdiinooqwbabcginoppqrrrsuwxznbjklmphbnoqrswyddehijllllqqsswcdiinooqw nbjklmphbnoqrswyddehijllllqqsswcdiinooqwbabcginoppqrrrsuwxznbjkl...
result:
ok ok (10 test cases)
Test #10:
score: 0
Accepted
time: 48ms
memory: 41824kb
input:
3 32852 zjcsxffjfgqgnvamcemwbswpnxmtxxlecsfpbbaygsvvfhesoexzicbclmctcwhaosjziphqkaechmrguyddlyelzaycvlrffhalklfxlnwkpopijuuusjbwnxqcayjfygjufkpyvnv zrwxifjqftg zrgxf xfggzrfxzr grffzxxzgffxxzfggfxxfgxfgxzfzzrffxxrrfxxfgrrfzgzzrrgzrfgrzrzfgrrxgrzzgxrgzgx xrrfrfxzgggxzgfxzrgfrzfzx grxxfzfgzzgxggzxfzgf...
output:
YES fzgxrfijqtwaaaaaaabbbbbccccccccccddeeeeeeffffffffgggghhhhhiijjjjjjkkkkllllllllmmmmmnnnnnoooppppppqqrssssssstuuuuuvvvvvvwwwwxxxxxxyyyyyyyzzz fzgxrfijqtw fzgxr fzgxrfzgxr fzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrfzgxrf fzgxrfzgxrfzgxrfzgxrfzgxr fzgxrfzgxrfzgxrfzgxrfzgx...
result:
ok ok (3 test cases)
Test #11:
score: 0
Accepted
time: 63ms
memory: 47424kb
input:
1 100000 mjrbblhjaodzaew bhdwmabzrloejarj waaarbwdlobbemzldjrbhjrajejo mojrjdzwaoearbbdajrjbjleabwhlldr abjebazdadlobwerbdoablarjjhlrdljrwmjrbje lohrmrrjrjalaljbzmwobbbdbbdbrarbjejawallraejabddrwajelojlzdjdwlraroejjehdb edbrlwajjba bbjaljddbjlbjwderaawljarreb bjraaewrjbdbdjll rjdbl rddjblbdjbrlrjrll...
output:
YES rljdbabeajwohmz rljdbabeajwohmzr rljdbabeajwohmzrrljdbabeajwo rljdbabeajwohmzrrljdbabeajworljd rljdbabeajwohmzrrljdbabeajworljdrljdbabe rljdbabeajwohmzrrljdbabeajworljdrljdbaberljdbabeajwohmzrrljdbabeajworljdrl rljdbabeajw rljdbabeajwrljdbabeajwrljdb rljdbabeajwrljdb rljdb rljdbrljdbrljdbrlj rlj...
result:
ok ok (1 test case)
Test #12:
score: 0
Accepted
time: 18ms
memory: 13928kb
input:
10000 2 oodmvpzyxi vpooodzmmidixopy 25 iosxruvcl l lllllllllllllllll lll llllllllll llll llllllll llllllllll l ll lllll llllllllll l lllllllll llllllllll l llllllllllllll l l ll l ll l llll l 4 plsftdw tsw sttttwsswws x 7 hbopcjceds scedhbgccdoccechsjbbahpopd hcq jcc klh hjcjchh jichchhcjchj 1 i 7 j...
output:
YES dimoopvxyz dimoopvxyzdimoop YES lciorsuvx l lllllllllllllllll lll llllllllll llll llllllll llllllllll l ll lllll llllllllll l lllllllll llllllllll l llllllllllllll l l ll l ll l llll l NO NO YES i NO YES bcccdefggijkklmnnnoppprsttuvwwxyy NO YES cghijkkkllnnpqqrtvwwz YES aadellssvw YES dy dyd d d...
result:
ok ok (10000 test cases)
Test #13:
score: 0
Accepted
time: 12ms
memory: 13996kb
input:
10000 4 a a a a 1 mqoukqzi 5 d hhhhrdhhhhhhhh hh gh hbhr 4 zcdufv fdvuzudvcf f f 1 s 12 mi mimimi m mmmmmmm m m m mm m mmm m mm 20 g g s g g g g g g g k g k g g g g u g g 11 f f f f f f f f f f f 9 gv v vvvvvvvv vvvv vvvvv v vvv vv vvvvvv 9 ti t tttt t ttt tt tt t tt 7 x k d r r w r 6 nc cf c v hdcc...
output:
YES a a a a YES ikmoqquz NO YES fduvcz fduvczfduv f f YES s YES mi mimimi m mmmmmmm m m m mm m mmm m mm NO YES f f f f f f f f f f f YES vg v vvvvvvvv vvvv vvvvv v vvv vv vvvvvv YES ti t tttt t ttt tt tt t tt NO NO YES abbbcccccccccccdeeeefffgghhhiiijjjjjkklllmmmmmmnnnnoooopppppqqrrrrssttttttuuuuuvv...
result:
ok ok (10000 test cases)
Test #14:
score: -100
Wrong Answer
time: 19ms
memory: 13948kb
input:
10000 1 t 8 ecj ejecjscecjje cecjejceejc ecjeceeecjcjcj cea oc ceec ecbc 34 zevdfbzayddtgja dea aaadc aadaa daa a a a x aa aaaaaaaa a aaa aa a a ba aaa aaaaa aaaaa aaa aaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaa aaaa aaa aa a aa aaa aaaa aaaaaaa aa aaa 1 xdvwkodeoicwnscdpkhwmxriaudyinlvbniaqhqnldbgtigvra...
output:
YES t NO NO YES aaaabbccddddddeefggghhhiiiiiijjkkllmnnnnoooppqqrrssttuvvvwwwxxyyz NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES bhilmqquuww NO NO NO YES dfgijpsttvvyyy YES bimswagiiijnoprabddfffggggghhiijlnnnooqqqrrttvvxxxyyyy bimswagiiijnopr bimswagiiijnoprbimsw NO NO NO YES aaaaaaccccddff...
result:
wrong answer Jury has the answer but participant has not (test case 5)