QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#352941 | #7773. 重排 | ANIG | 0 | 18ms | 8440kb | C++23 | 2.5kb | 2024-03-13 18:48:28 | 2024-03-13 18:48:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5;
string s;
int p[N],n,op,g[N],lst,rs[N];
signed main(){
cin>>s;
n=s.size();
for(int i=0;i<n;i++)p[s[i]-'a']++;
for(int i=0;i<26;i++){
if(p[i]){
op=i;
for(int j=i;j<26;j++)p[j-i]=p[j];
for(int j=26-i;j<26;j++)p[j]=0;
break;
}
}
cout<<(char)(op+'a');
p[0]--;lst=0;
for(int i=2;i<=n;i++){
for(int j=25;j>=0;j--){
if(lst&&j>lst)continue;
if(!p[j])continue;
if(!j){
rs[0]=1e9;
for(int k=1;k<26;k++){
if(!g[k]){
rs[k]=rs[k-1]+p[k];
continue;
}
if(p[k]/g[k]>rs[k-1])rs[k]=rs[k-1]+(p[k]-(g[k]*rs[k-1]))/(g[k]+1);
else rs[k]=p[k]/g[k];
}
int k=25;
while(p[0]--){
cout<<(char)('a'+op);
string s="";
while(1){
if(!g[k]){
if(!p[k]){
k--;
continue;
}else{
cout<<s<<(char)('a'+op+k);
p[k]--;
break;
}
}
if(p[k]>=rs[k-1]*g[k]+g[k]+1){
cout<<s;
for(int t=1;t<=g[k]+1;t++)cout<<(char)('a'+op+k);
p[k]-=g[k]+1;
break;
}else{
for(int t=1;t<=g[k];t++)s+=(char)('a'+op+k);
k--;
}
}
}
exit(0);
}
g[j]++;p[j]--;
int mx=1e9;
for(int k=1;k<26;k++){
if(!g[k]){
mx+=p[k];
continue;
}
if(p[k]/g[k]>mx)mx+=(p[k]-(g[k]*mx))/(g[k]+1);
else mx=p[k]/g[k];
}
if(mx<p[0]){
g[j]--;
p[j]++;
continue;
}
lst=j;
cout<<(char)(j+'a'+op);
break;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 1ms
memory: 7684kb
input:
mmmmmmmmm
output:
mmmmmmmmm
result:
ok single line: 'mmmmmmmmm'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7668kb
input:
qqymfqgj
output:
fyqqqmjg
result:
ok single line: 'fyqqqmjg'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7564kb
input:
wtzyztttz
output:
tywtztztz
result:
ok single line: 'tywtztztz'
Test #4:
score: -10
Wrong Answer
time: 1ms
memory: 7688kb
input:
bcbccccbcc
output:
bccbccb
result:
wrong answer 1st lines differ - expected: 'bccbccbccc', found: 'bccbccb'
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 1ms
memory: 7688kb
input:
bbbbbbbcbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
output:
bbcbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb`
result:
wrong answer 1st lines differ - expected: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc', found: 'bbcbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb`'
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 1ms
memory: 7572kb
input:
elppjxhjnqephxnnleeepqllpeellqpleexepxlqnpelnlpgplxejlpllppleppnllhjhppgneleghexegqpxpqlqhpnenhlgjjepelllpexplqeppexpqeghpplnpxegeeehqgnhxeqllplphlxpppqnhqephlqnxenlehpeplnqenheejhxqxleeljepehlngepgpxpllppeeheelpplpexpqgheelllplpqnllexlphepghllxnnepqjpqepjeheqqghhejhlnlnlqleeplepxhnlqlnppjpeelqeelxg...
output:
eppppnllllllllllllljjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexe...
result:
wrong answer 1st lines differ - expected: 'eppppnllllllllllllljjjjjjjjjjj...llllllllllleppppnllllllllllllll', found: 'eppppnllllllllllllljjjjjjjjjjj...lellllllllllllllellllllllllllll'
Subtask #4:
score: 0
Wrong Answer
Test #46:
score: 0
Wrong Answer
time: 18ms
memory: 8440kb
input:
ksetiktesataqqwcetteiqcqtwakaiaaaqciceaticteectqqtcaectqtsticctqeqeeiieecaqtctctqqeqitqtttccccctikacktaaqteictwstcitttectaitttiqeqasskkqaateeaatqaetttccesqitiecatgqqaqitwqtaqqcqittittiswcweaiqicqiecwtccakaattgtickccqkqckaaewkekccggtiiqqsttcqactiqeaeqtiigeekettaieekectqqckqqteiceacwecktaiteaceaqkqeic...
output:
atsqqqkiiiiiiiiiggggeeeeeeeeeeeeeecccccccccccccccccccccccccccawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawawa...
result:
wrong answer 1st lines differ - expected: 'atsqqqkiiiiiiiiiggggeeeeeeeeee...eeecccccccccccccccccccccccccccc', found: 'atsqqqkiiiiiiiiiggggeeeeeeeeee...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'