QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203954 | #87. Devil's Share | Ahmed57# | 27 | 1305ms | 3928kb | C++23 | 3.4kb | 2023-10-06 22:43:29 | 2024-07-04 02:17:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int arr[5];string s;
string maa;string w;int k,x;
string lol[4*4*4*4][13];
void rec(){
bool ss = 0;
for(int i = 1;i<=4;i++){
if(arr[i]){
ss = 1;
arr[i]--;s+=char(i+'0');
rec();
arr[i]++;
s.pop_back();
}
}
if(ss==0){
string ma;
for(int j = 0;j<s.size()-k+1;j++){
string se;
for(int e = j;e<j+k;e++)se+=s[e];
if(ma.empty())ma = se;
ma = max(ma,se);
}
if(maa.empty()||ma<maa){
maa = ma;
w = s;
}
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int t;cin>>t;
int a;cin>>a;
if(a>2){
for(int q = 1;q<4*4*4*4;q++){
int de = 0;
int e = q;
int sum = 0;
for(int i = 1;i<=4;i++){
arr[i] = e%4;
e/=4;
sum+=arr[i];
}for(int K = 1;K<=sum;K++){
k = K;
maa = "";
rec();
lol[q][k] = w;
}
}
k = a;
for(int z = 0;z<t;z++){
if(z)cin>>k;
int de = 0;
for(int i = 1;i<=4;i++){
cin>>arr[i];
}
for(int i = 5;i<10;i++)cin>>x;
for(int i = 4;i>=1;i--){de*=4;de+=arr[i];}
cout<<lol[de][k]<<endl;
}
}else{
k = a;
for(int q = 0;q<t;q++){
if(q)cin>>k;
int arr[10] = {0};
for(int i = 1;i<10;i++)cin>>arr[i];
if(k<2){
for(int i = 1;i<10;i++){
for(int j = 0;j<arr[i];j++){
cout<<char(i+'0');
}
}
cout<<endl;
}else{
int su = 0;
string v;int ind = 0;
for(int i = 9;i>=1;i--){
su+=arr[i];
if(su>=2){
su-=arr[i];
ind = i;break;
}else{
for(int j = 0;j<arr[i];j++){
v+=char(i+'0');
}
arr[i] = 0;
}
}
if(su==1){
int lol = 1;
while(arr[ind]){
while(arr[lol]==0)lol++;
v+=char(lol+'0');
arr[lol]--;
if(arr[ind]){
v+=char(ind+'0');
arr[ind]--;
}
}
for(int i = 1;i<10;i++){
for(int j = 0;j<arr[i];j++){
v+=char(i+'0');
}
}
}else{
int lol = 1;
while(arr[ind]){
if(arr[ind]){
v+=char(ind+'0');
arr[ind]--;
}
while(lol<10&&arr[lol]==0)lol++;
if(lol<10){
v+=char(lol+'0');
arr[lol]--;
}
}
for(int i = 1;i<10;i++){
for(int j = 0;j<arr[i];j++){
v+=char(i+'0');
}
}
}
reverse(v.begin(),v.end());
cout<<v<<endl;
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 13
Accepted
Test #1:
score: 13
Accepted
time: 1304ms
memory: 3664kb
input:
1536 4 2 1 2 2 0 0 0 0 0 2 3 2 3 3 0 0 0 0 0 3 1 2 0 3 0 0 0 0 0 4 2 2 3 2 0 0 0 0 0 1 3 3 2 2 0 0 0 0 0 3 1 2 2 0 0 0 0 0 0 3 2 1 2 3 0 0 0 0 0 6 1 3 3 0 0 0 0 0 0 4 1 0 1 2 0 0 0 0 0 4 2 1 2 3 0 0 0 0 0 4 2 3 0 2 0 0 0 0 0 5 3 2 3 3 0 0 0 0 0 3 2 2 1 1 0 0 0 0 0 3 2 3 2 0 0 0 0 0 0 8 1 3 1 3 0 0 0...
output:
3112344 12233341414 241244 312312344 1112223344 22133 23341144 2122333 1344 31312444 2121244 31131223444 212134 2122133 12223444 13444 12223334 13341144 2313132244 12342424 122233 211444 11223 11223344 11222334 13 223131314 323244 2323234 11334 3123123444 114 122233414 11333 12234 222334 3111444 144...
result:
ok Correct!
Subtask #2:
score: 14
Accepted
Test #2:
score: 14
Accepted
time: 32ms
memory: 3672kb
input:
35960 2 0 0 5 2 0 0 17 0 7 2 0 6 0 15 0 0 0 4 5 2 3 0 0 1 20 0 0 0 8 2 0 5 0 0 15 0 5 7 0 2 0 0 2 11 0 0 4 0 10 2 0 14 0 0 11 0 0 6 1 2 0 0 10 3 0 0 8 0 1 2 0 1 9 0 2 0 0 6 0 2 0 0 0 0 5 0 12 7 3 2 0 0 5 0 0 2 0 8 9 2 7 2 0 0 0 0 0 6 8 2 0 0 0 4 1 0 3 18 0 2 0 0 14 4 8 0 0 0 1 2 0 2 0 0 0 13 3 9 0 2...
output:
7777777777777777749493939393939 888844444444444444422929292929 55555555555555555959595949191919 77777555555555555558582828282828 777744449494949494949493939 55555555555222222228282828282829 4443373737373737373739 553333383838383828 888888877777777777755595959 888888898969693939393939 888888229191919...
result:
ok Correct!
Test #3:
score: 0
Accepted
time: 8ms
memory: 3928kb
input:
23426 2 34 0 0 0 0 3 0 0 8 2 20 1 0 0 0 21 0 0 0 2 18 0 0 0 5 0 0 0 18 2 8 18 0 0 0 27 0 0 0 2 0 0 2 47 0 0 0 0 4 2 0 0 0 36 9 0 5 0 0 2 7 0 0 15 0 0 29 0 0 2 2 0 27 0 0 0 20 0 0 2 0 0 0 3 29 0 0 11 0 2 0 0 0 11 0 0 25 14 0 2 0 7 0 16 0 22 0 0 0 2 0 0 0 1 0 22 20 0 0 2 0 0 0 37 0 3 0 7 0 2 20 0 0 0 ...
output:
666111111111111111111111111111919191919191919 261616161616161616161616161616161616161616 55555191919191919191919191919191919191919 62626262626262626262626262626262626261616161616161616 44444444444444444444444444444444444444444444449493939 55555555544444444444444444444444444444444747474747 7777777474...
result:
ok Correct!
Test #4:
score: 0
Accepted
time: 7ms
memory: 3668kb
input:
19600 2 0 7 0 9 0 0 3 32 0 2 0 0 0 0 23 22 4 2 0 2 0 0 6 0 0 2 33 0 10 2 0 12 0 7 0 11 21 0 0 2 41 0 0 5 3 0 2 0 0 2 19 0 0 13 6 0 0 0 13 2 12 6 0 0 9 0 0 24 0 2 0 7 2 6 0 0 0 0 36 2 3 0 18 0 0 28 0 2 0 2 0 0 2 0 0 37 3 0 9 2 8 0 0 10 29 0 0 4 0 2 18 10 0 0 2 0 0 21 0 2 0 0 29 8 0 0 9 5 0 2 28 0 0 0...
output:
888888888888878787848484848484848484828282828282828 777766666666666666666666665555555555555555555555858 777777777777777777777777777777779796969393939393939 666666666676747474747474747272727272727272727272727 555444441111111111111111111111111111111111111111717 5555554444444444444111111191919191919191...
result:
ok Correct!
Test #5:
score: 0
Accepted
time: 40ms
memory: 3900kb
input:
40215 2 5 0 0 2 3 4 5 0 2 2 0 1 4 0 2 4 0 3 7 2 2 0 0 0 0 18 12 0 0 2 0 13 11 0 16 0 0 0 0 2 7 0 6 2 1 0 0 0 5 2 4 0 0 0 0 0 8 2 3 2 5 2 0 0 2 0 2 7 3 2 3 0 0 2 3 4 4 5 0 2 0 0 3 1 0 0 0 12 2 2 2 13 3 0 1 0 0 1 1 2 0 0 10 0 4 0 0 0 18 2 0 1 7 0 0 6 0 0 1 2 3 0 6 3 3 6 0 0 0 2 0 5 0 4 4 1 7 0 0 2 0 0...
output:
777776666555441111919 888666659593939393929 66666666676767676767676767671717 3333333335353525252525252525252525252525 544333333111919191919 88777777771191919 888888877552211191919 777766665554848181818 888888888888433939 533322222222222221819 99995959595939393939393939393939 336363636363629 55544433...
result:
ok Correct!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
1000 2 346 0 0 0 0 0 325 0 305 2 341 0 0 0 304 0 0 0 325 2 0 315 0 0 0 0 0 335 346 2 299 0 0 0 0 296 325 0 0 2 0 0 324 286 0 298 0 0 0 2 0 0 0 0 0 0 345 323 313 2 0 0 0 0 0 305 0 320 294 2 0 0 0 308 339 0 0 301 0 2 323 0 0 317 0 0 0 0 278 2 0 292 342 0 0 324 0 0 0 2 0 0 0 285 0 342 0 324 0 2 310 0 2...
output:
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
result:
ok Correct!
Test #7:
score: 0
Accepted
time: 5ms
memory: 3728kb
input:
1000 2 232 0 0 223 0 211 0 0 244 2 0 0 0 0 233 277 222 0 252 2 0 250 230 0 0 0 241 0 242 2 248 241 248 0 0 219 0 0 0 2 223 0 0 0 253 240 226 0 0 2 0 0 0 251 0 235 0 239 263 2 267 245 0 220 260 0 0 0 0 2 261 0 0 0 0 256 250 221 0 2 0 240 229 0 0 236 243 0 0 2 0 236 0 248 0 252 242 0 0 2 0 0 239 250 0...
output:
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666644444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...
result:
ok Correct!
Test #8:
score: 0
Accepted
time: 5ms
memory: 3672kb
input:
1000 2 84 122 93 126 108 97 117 115 115 2 110 100 118 106 104 112 100 118 128 2 107 102 103 109 119 97 93 118 101 2 128 107 106 97 88 90 97 91 97 2 134 122 108 95 103 105 102 95 112 2 88 110 128 99 94 93 105 113 114 2 111 108 118 97 90 99 93 89 115 2 91 98 106 110 111 102 106 96 95 2 110 98 124 110 ...
output:
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888877777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777766666666666666666666666666666666666666666666666666666666666666666666...
result:
ok Correct!
Test #9:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
100 2 1076 1058 1108 1113 1118 1160 1056 1150 1094 2 1097 1101 1124 1098 1085 1113 1122 1090 1081 2 1062 1049 1138 1063 1088 1029 1109 1149 1109 2 1005 1079 990 1015 1053 1013 1043 1059 995 2 1041 1043 1079 1092 1040 1079 1104 1057 1016 2 1012 1075 984 1082 1082 993 969 1019 987 2 939 1033 988 1061 ...
output:
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...
result:
ok Correct!
Test #10:
score: 0
Accepted
time: 3ms
memory: 3884kb
input:
10 2 10734 10761 10776 10789 10842 10844 10973 10952 10904 2 10639 10677 10586 10820 10717 10667 10636 10594 10659 2 10253 10248 10111 10247 10186 10246 10194 10096 10099 2 10301 10375 10306 10267 9994 10102 10124 10006 10162 2 10894 10878 10645 10624 10493 10697 10843 10738 10719 2 9953 10322 9896 ...
output:
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...
result:
ok Correct!
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 1305ms
memory: 3664kb
input:
26488 21 7 19 0 0 0 0 0 0 0 3 15 21 0 0 0 0 0 0 0 7 4 35 0 0 0 0 0 0 0 5 28 12 0 0 0 0 0 0 0 22 40 3 0 0 0 0 0 0 0 1 7 6 0 0 0 0 0 0 0 5 12 21 0 0 0 0 0 0 0 18 27 13 0 0 0 0 0 0 0 2 36 6 0 0 0 0 0 0 0 15 19 14 0 0 0 0 0 0 0 34 17 20 0 0 0 0 0 0 0 11 17 5 0 0 0 0 0 0 0 19 10 12 0 0 0 0 0 0 0 28 29 9 ...
output:
131134 1112223 232323 2224 11122333 1114 21112333 11244 133314 2333 223 22244 112224 122233 112224 11122234 11122234 21224 2333 2121244 113 211224 11122334 11244 1123 222334 131144 333 11233 314 22233 222333 1124 212333 113232324 21211333 111224 21211234 1122244 1223...
result:
FAIL Condition failed: "s.length() == S"
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%