QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708939 | #8349. 零和 | ship2077 | 100 ✓ | 9ms | 4024kb | C++23 | 1012b | 2024-11-04 09:53:46 | 2024-11-04 09:53:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
mt19937 mt(time(NULL));
constexpr int M=1005;
int K,n,m,k,a[M],f[M],p[M];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
void solve(){ K=read()-1;
while (1){ n=24;m=0;k=K;f[0]=1;
for (int i=1;i<=24;i++){
a[i]=mt()%5+1;m+=a[i];
for (int j=m;j>=a[i];j--) f[j]+=f[j-a[i]];
}
iota(p+1,p+m+1,1);
sort(p+m/2+1,p+m+1,[&](int x,int y){return f[x]>f[y];});
for (int i=m/2+1;i<=m;i++)
while (k>=f[p[i]]){
k-=f[p[i]];a[++n]=-p[i];
if (n>30) break;
}
for (int i=0;i<=m;i++) f[i]=0;
if (n<=30&&!k){
printf("%d\n",n);
for (int i=1;i<=n;i++)
printf("%d%c",a[i]," \n"[i==n]);
return;
}
}
}
int main(){int T=read();while (T--) solve();return 0;}
詳細信息
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 3ms
memory: 3896kb
input:
1000 4 10 9 7 5 9 4 4 10 8 2 10 8 8 4 2 10 4 9 9 8 9 6 9 5 6 9 1 2 5 8 4 4 8 2 2 7 6 8 2 3 1 1 3 1 10 6 3 4 1 6 7 1 5 7 7 3 6 3 3 9 6 9 5 7 5 9 8 3 5 2 4 9 3 10 2 10 10 3 1 9 4 8 9 6 6 6 7 7 7 10 1 2 3 2 6 6 8 1 3 10 8 5 7 8 2 7 9 3 1 9 9 1 10 6 7 9 9 7 9 1 2 7 3 1 5 4 9 2 6 4 9 9 10 4 4 5 9 10 2 2 ...
output:
27 3 1 1 2 4 4 5 2 1 4 2 5 2 4 3 3 3 1 1 3 4 3 3 1 -65 -65 -65 27 4 3 1 4 5 3 3 2 3 5 3 2 1 3 4 2 4 4 4 5 5 4 3 4 -79 -79 -81 26 3 2 2 4 1 2 4 5 5 3 3 2 3 2 1 5 4 5 2 1 3 4 5 1 -71 -71 26 3 3 4 3 2 3 2 4 2 3 3 5 4 3 4 3 2 1 1 2 4 2 1 3 -66 -66 28 2 2 1 4 1 5 1 3 5 1 5 2 1 5 5 5 5 5 2 1 5 2 1 1 -70 -...
result:
ok Accepted
Subtask #2:
score: 15
Accepted
Dependency #1:
100%
Accepted
Test #2:
score: 15
Accepted
time: 3ms
memory: 3960kb
input:
1000 42 56 95 81 26 68 42 3 83 6 37 52 5 82 59 10 43 90 44 55 83 8 43 14 94 84 92 61 10 98 46 58 43 49 81 29 36 3 93 38 70 86 54 89 75 28 87 74 56 22 47 89 90 26 76 80 55 90 60 32 58 67 70 94 52 95 78 70 39 40 69 99 18 24 32 33 23 95 19 80 98 59 79 57 69 35 25 72 27 72 57 13 55 37 90 59 53 10 2 84 4...
output:
29 3 1 1 2 4 4 5 2 1 4 2 5 2 4 3 3 3 1 1 3 4 3 3 1 -63 -63 -65 -65 -65 26 4 3 1 4 5 3 3 2 3 5 3 2 1 3 4 2 4 4 4 5 5 4 3 4 -76 -81 29 3 2 2 4 1 2 4 5 5 3 3 2 3 2 1 5 4 5 2 1 3 4 5 1 -68 -70 -71 -72 -72 28 3 3 4 3 2 3 2 4 2 3 3 5 4 3 4 3 2 1 1 2 4 2 1 3 -63 -65 -66 -66 28 2 2 1 4 1 5 1 3 5 1 5 2 1 5 5...
result:
ok Accepted
Subtask #3:
score: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #3:
score: 15
Accepted
time: 3ms
memory: 4024kb
input:
1000 1458 1427 1927 1845 764 1218 986 13 1479 494 1405 1711 88 1701 536 1286 1735 711 63 439 469 1726 739 1496 1055 1775 1946 860 134 742 1296 188 373 1156 230 1366 1123 1601 1015 481 1177 250 723 1265 1254 416 329 489 661 305 1895 1057 1676 676 1972 1031 1721 1483 1046 387 1522 1936 1778 1526 27 11...
output:
28 1 5 1 2 5 5 4 4 1 2 3 1 2 5 3 1 4 3 1 5 5 3 3 3 -64 -69 -71 -71 26 2 4 5 3 5 5 5 1 5 2 1 4 2 1 1 1 5 1 4 1 4 4 2 1 -62 -69 30 5 4 3 2 1 1 3 3 5 4 5 4 1 2 2 4 2 4 1 2 5 1 1 2 -60 -61 -64 -66 -66 -66 30 2 4 1 1 3 1 3 1 4 5 1 3 5 4 3 4 1 3 1 3 2 3 2 3 -56 -59 -59 -61 -62 -62 29 3 5 4 1 1 5 5 5 5 4 2...
result:
ok Accepted
Subtask #4:
score: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #4:
score: 15
Accepted
time: 4ms
memory: 3836kb
input:
1000 8882 3890 5276 2293 7017 8729 4107 8330 9804 3437 7125 8266 505 902 10 4246 46 4186 7869 6510 3510 681 8065 2419 1575 2776 2762 5567 3150 5914 4695 6152 2758 5157 1407 5964 8947 8203 7821 3411 3115 8356 8240 3506 1618 1108 4024 5791 2644 3315 3577 9512 5256 3454 7378 9383 4904 6094 8422 7100 71...
output:
30 1 5 1 2 5 5 4 4 1 2 3 1 2 5 3 1 4 3 1 5 5 3 3 3 -61 -63 -67 -69 -70 -72 29 2 4 5 3 5 5 5 1 5 2 1 4 2 1 1 1 5 1 4 1 4 4 2 1 -61 -63 -64 -65 -68 26 5 5 1 4 3 1 2 1 2 1 1 5 3 3 2 2 5 1 2 5 3 5 4 5 -61 -65 30 5 5 5 3 1 5 3 3 3 5 5 3 3 2 2 4 1 4 2 3 3 3 1 5 -69 -71 -73 -75 -79 -79 28 2 3 4 4 5 5 4 1 5...
result:
ok Accepted
Subtask #5:
score: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #5:
score: 15
Accepted
time: 6ms
memory: 3848kb
input:
1000 96341 68443 37369 95002 5050 28444 863 40283 5948 58559 90074 93374 20434 66458 42427 81860 19058 44240 61491 29065 18196 59230 70644 48078 44160 52618 31944 3993 66326 63711 62648 80986 90080 12593 36140 908 97838 9909 62779 18661 92388 86436 83715 49365 10604 17467 65898 31682 64543 37267 202...
output:
30 2 3 5 1 4 5 4 4 5 2 4 1 5 2 3 4 1 1 1 4 3 5 4 5 -57 -69 -71 -73 -75 -78 28 3 4 1 2 3 2 1 3 1 1 4 4 5 4 3 5 2 2 5 3 3 2 1 3 -51 -56 -62 -67 30 4 5 5 5 3 1 1 2 4 5 5 2 2 1 4 4 4 3 5 2 5 5 2 3 -64 -68 -73 -76 -82 -82 29 5 1 4 4 2 4 1 5 3 1 4 3 4 1 4 3 4 2 4 1 2 2 4 3 -53 -57 -64 -68 -70 29 3 1 5 3 2...
result:
ok Accepted
Subtask #6:
score: 25
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #6:
score: 25
Accepted
time: 9ms
memory: 3960kb
input:
1000 68691 709038 403562 87832 620545 194650 877186 754984 970483 972817 576860 95921 320214 328151 977559 803543 893740 413219 868313 153241 553644 186975 758312 166278 963660 596237 523965 976575 92819 743171 220709 536964 847991 151853 256090 912309 286952 609500 293131 143200 850426 155262 98688...
output:
30 4 1 4 1 5 2 4 5 5 3 5 3 4 4 4 4 3 1 1 1 4 4 4 3 -59 -67 -70 -75 -76 -76 29 3 2 4 5 1 5 3 5 2 1 1 3 4 2 2 1 2 2 1 5 1 4 4 3 -38 -59 -61 -62 -66 29 2 1 5 4 1 5 2 1 4 5 3 3 5 4 3 5 4 3 2 1 1 5 5 1 -48 -60 -65 -68 -70 29 2 3 4 2 4 4 4 2 2 5 3 5 2 5 4 3 3 1 4 1 4 4 3 1 -55 -66 -72 -73 -73 30 5 1 4 4 2...
result:
ok Accepted