QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#450295 | #7773. 重排 | Acoipp | 0 | 7ms | 24152kb | C++14 | 1.3kb | 2024-06-22 08:35:46 | 2024-06-22 08:35:46 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define N 1000005
using namespace std;
ll n,i,rk[N],head[N],ls[N],rs[N],las[N],temp[N],pos,trk[N],thd[N],tla[N];
pair<ll,ll> tmp[N];
char s[N];
inline bool cmp(ll a,ll b){return tmp[a]<tmp[b];}
inline void merge(ll a,ll b){rs[las[a]]=head[b],ls[head[b]]=las[a],las[a]=las[b];}
inline void solve(ll len){
if(len==1){
for(ll i=head[1];i;i=rs[i]) cout<<s[i];
cout<<endl;
return ;
}
ll k = 1;
while(k+1<=len&&rk[k+1]==rk[k]) k++;
if(len-k>=k){
for(ll i=1;i<=k;i++) merge(i,len-i+1),tmp[i]=make_pair(rk[i],rk[len-i+1]);
for(ll i=k+1;i<=len-k;i++) tmp[i]=make_pair(rk[i],0);
len -= k;
}
else{
for(ll i=1;i<=len-k;i++) merge(i,len-i+1),tmp[i]=make_pair(rk[i],rk[len-i+1]);
for(ll i=len-k+1;i<=k;i++) tmp[i]=make_pair(rk[i],0);
len = k;
}
for(ll i=1;i<=len;i++) temp[i]=i;
sort(temp+1,temp+len+1,cmp);
for(ll i=1;i<=len;i++) thd[i]=head[temp[i]],tla[i]=las[temp[i]];
for(ll i=1,j=1;i<=len;i=j){
pos++;
for(j=i;j<=len;j++) if(tmp[temp[i]]!=tmp[temp[j]]) break;
for(ll k=i;k<j;k++) trk[k]=pos;
}
for(ll i=1;i<=len;i++) rk[i]=trk[i],head[i]=thd[i],las[i]=tla[i];
solve(len);
}
int main(){
ios::sync_with_stdio(false);
cin>>(s+1),n=strlen(s+1);
sort(s+1,s+n+1);
for(i=1;i<=n;i++) rk[i]=s[i]-'a'+1,head[i]=i,las[i]=i,ls[i]=rs[i]=0;
solve(n);
return 0;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
mmmmmmmmm
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #16:
score: 20
Accepted
time: 0ms
memory: 22036kb
input:
bbbbbbbcbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
output:
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
result:
ok single line: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc'
Test #17:
score: -20
Time Limit Exceeded
input:
aaaaaaaabcaabacacaaaacaaabaaaabaabaaaaac
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #31:
score: 30
Accepted
time: 0ms
memory: 22056kb
input:
elppjxhjnqephxnnleeepqllpeellqpleexepxlqnpelnlpgplxejlpllppleppnllhjhppgneleghexegqpxpqlqhpnenhlgjjepelllpexplqeppexpqeghpplnpxegeeehqgnhxeqllplphlxpppqnhqephlqnxenlehpeplnqenheejhxqxleeljepehlngepgpxpllppeeheelpplpexpqgheelllplpqnllexlphepghllxnnepqjpqepjeheqqghhejhlnlnlqleeplepxhnlqlnppjpeelqeelxg...
output:
eppppnllllllllllllljjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexe...
result:
ok single line: 'eppppnllllllllllllljjjjjjjjjjj...llllllllllleppppnllllllllllllll'
Test #32:
score: 0
Accepted
time: 4ms
memory: 24136kb
input:
vqfiiyoutipohliojhwhyohiqholfovovhwvuffvifvlffiuwhphmoofjyhhjtfimiisjqwwjtvlotmpivlvyoilvwhhygofhvffoiftmyhpvjqypqfoihfhfjisoiwjujuqvijofilwqjjmqfymtiivfoplifwjplvfvfqvstlihfotqjfylowttwsyvsifvfhptpfovqilvujfyltohvmjtijhpiyffpvyiioyvjqpfjhshowphuttflpfojiovhvtiwfymfvwyooftimyumoomosjlitviowfhtoovlov...
output:
fwvvuuuuuuuttttttttttttttttttttttttttttssssssssssssssssssssqqqqqqqqqqqqqqqqqqqqqqqqqqqppppppppppppppppppppppppppppppppppppppppppppppoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooommmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmllllllllllllllllllll...
result:
ok single line: 'fwvvuuuuuuuttttttttttttttttttt...uuttttttttttttttttttttttttttttt'
Test #33:
score: 0
Accepted
time: 0ms
memory: 24152kb
input:
hdkfjdurfkufuqjhfrhodhrqqsjjaduooafqrkfjhufjqfuqqjhryrahhyggkorjqfjraohrfrqkfjjqarkdfryrooyuoffuqfyyfhdjmhghumjojuafkdrqmohrahhyaaouqfjjojgjrykrhduoshqahquhhoqahokgkfhaojhkjkukafqqrdrsyfqahuqhqduqqufujohjgauoarjagfaaamjuqoqhqkrouuoryhhqyodjfqgjhykhryorguqkoffuyaqgoqodjragfrgkyojmodkuhyjyffuyyjajfhrf...
output:
aurrrqqqqqqqqqqqqoooooooooooooooooooooooooooooooooooooooooooommmmmmmmmmmmmmmmmmkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhggg...
result:
ok single line: 'aurrrqqqqqqqqqqqqooooooooooooo...ooooooooooooooooooooooooooooooo'
Test #34:
score: 0
Accepted
time: 7ms
memory: 22176kb
input:
uksbcbnccbkuqbtebuykgybzbzzbgtznktgzgutckyxbetckqbzzybfybqtykskkccgzskutkqgzyygszkeqgyecbkzbgckktshzgzkbkbztbybgtnntzyezbgtkzgncqkctxegbztzyyggnbyybbuykghsxegkekxhsuynkzyxbzxkcnksezeyejgnytegsyzcgkkyygbxstgytkyeuuzzktknzkeuksnkzgckbzcnegnbkzkzzgzqjzgyshyeeggnceggcyhctqscftbtczcbtyzyskcyyezyyfekyfcgb...
output:
bzyttsssssssssssssssssssssssssssqqqqqqqqqqqqqqqqqqqnnnnnnnnnnnnnnnnnnnnnnkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjhhhhhhhhgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffff...
result:
ok single line: 'bzyttsssssssssssssssssssssssss...qqqqqqqqnnnnnnnnnnnnnnnnnnnnnnn'
Test #35:
score: -30
Time Limit Exceeded
input:
hhhccchhhcchhhcchccchcchccccchcchhchhchcchhhcchcccchhcchchccchhccccccchccccchhchcchcccchchhcchchccccchhhccccchhhchccchhccccchhchhccchccchchccccchhhccccchhcchchhchchchcchcchhhccccccccccchhhhcchchhcchhhhcchchcchcccchcchcccchchcccchcccchhhhccchcccchccccchhhcchcchchhccchchhhchcchcchcccchcchccchhccchhchc...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #46:
score: 0
Time Limit Exceeded
input:
ksetiktesataqqwcetteiqcqtwakaiaaaqciceaticteectqqtcaectqtsticctqeqeeiieecaqtctctqqeqitqtttccccctikacktaaqteictwstcitttectaitttiqeqasskkqaateeaatqaetttccesqitiecatgqqaqitwqtaqqcqittittiswcweaiqicqiecwtccakaattgtickccqkqckaaewkekccggtiiqqsttcqactiqeaeqtiigeekettaieekectqqckqqteiceacwecktaiteaceaqkqeic...