QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#393999 | #1840. K-onstruction | NATURAL6 | AC ✓ | 351ms | 4056kb | C++14 | 1.3kb | 2024-04-19 20:25:53 | 2024-04-19 20:25:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
mt19937 fxk(time(0));
inline int rnd(int x){return fxk()%x+1;}
inline int qread()
{
int a=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
return a*f;
}
int T,K,n,sum,a[40],p[100010];
long long dp[100010];
inline bool cmp(int x,int y){return dp[x]>dp[y];}
inline void solve()
{
K=qread();
while(1)
{
memset(dp,0,(sum+1)<<3);
memset(a,0,(n+1)<<2);
sum=n=0;dp[0]=1;
for(int i=1;i<=15;++i)
{
a[i]=rnd(5);sum+=a[i];
for(int j=sum;j>=a[i];--j)dp[j]+=dp[j-a[i]];
}
for(int i=0;i<=sum;++i)p[i]=i;
sort(p+1,p+sum+1,cmp);
for(int i=16,lp=0;i<=30;++i)
{
if(dp[0]==K){n=i-1;break;}
lp=1;
while(dp[0]+dp[p[lp]]>K)++lp;
if(lp>sum)break;
a[i]=-p[lp];
for(int j=0;j<=sum+a[i];++j)dp[j]+=dp[j-a[i]];
sort(p+1,p+sum+1,cmp);
}
if(dp[0]==K)
{
if(!n)n=30;
printf("%d\n",n);
for(int i=1;i<=n;++i)printf("%d ",a[i]);puts("");
return ;
}
}
return ;
}
int main()
{
T=qread();
while(T--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3936kb
input:
2 3 16
output:
17 2 4 1 1 1 5 5 4 5 4 4 5 3 2 5 -51 -51 18 4 2 3 3 5 5 5 2 5 3 1 1 2 2 5 -45 -47 -47
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 2ms
memory: 3964kb
input:
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
15 2 4 1 1 1 5 5 4 5 4 4 5 3 2 5 16 4 2 3 3 5 5 5 2 5 3 1 1 2 2 5 -48 17 5 1 1 3 1 1 3 5 4 3 5 1 1 4 4 -42 -42 18 2 4 4 4 2 2 1 2 1 1 3 1 4 1 1 -33 -33 -33 19 5 1 2 5 3 4 5 5 1 2 1 2 1 2 1 -40 -40 -40 -40 16 1 1 1 2 2 5 5 5 2 2 3 1 3 1 5 -1 19 1 2 1 2 3 3 2 4 2 3 1 4 2 4 3 -1 -37 -37 -37 18 4...
result:
ok correct (1000 test cases)
Test #3:
score: 0
Accepted
time: 2ms
memory: 3948kb
input:
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 ...
output:
19 2 4 1 1 1 5 5 4 5 4 4 5 3 2 5 -34 -44 -50 -51 18 4 2 3 3 5 5 5 2 5 3 1 1 2 2 5 -32 -46 -48 17 5 1 1 3 1 1 3 5 4 3 5 1 1 4 4 -29 -37 24 2 4 4 4 2 2 1 2 1 1 3 1 4 1 1 -9 -29 -31 -32 -32 -33 -33 -33 -33 18 5 1 2 5 3 4 5 5 1 2 1 2 1 2 1 -28 -36 -40 20 1 1 1 2 2 5 5 5 2 2 3 1 3 1 5 -11 -33 -39 -3...
result:
ok correct (1000 test cases)
Test #4:
score: 0
Accepted
time: 298ms
memory: 3944kb
input:
1000 993583 891827 976796 828946 983149 933824 989543 985227 981826 917123 995813 961139 945833 875509 983784 994507 998827 941562 865682 996623 971299 953499 918651 971707 966313 980053 996657 976037 870307 935389 927903 998826 923969 987837 905739 996643 979733 952467 881278 929789 956447 976709 9...
output:
30 4 4 3 1 1 4 2 2 1 1 5 4 1 3 4 -20 -20 -1 -1 -1 -1 -1 -1 -1 -1 -28 -33 -35 -36 -36 30 3 3 4 5 2 3 4 5 1 1 2 5 4 2 1 -22 -22 -1 -1 -1 -1 -1 -1 -1 -1 -37 -39 -41 -42 -42 28 4 5 4 2 2 1 4 1 3 4 3 3 1 1 2 -20 -20 -1 -1 -1 -1 -1 -1 -1 -1 -29 -32 -34 30 4 3 3 4 2 3 2 4 5 5 1 2 5 3 2 -24 -24 -1 -1 -1 ...
result:
ok correct (1000 test cases)
Test #5:
score: 0
Accepted
time: 7ms
memory: 3944kb
input:
1000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 ...
output:
24 2 1 4 5 4 3 3 2 3 5 3 1 3 4 1 -22 -22 -1 -33 -41 -42 -44 -44 -44 24 2 4 5 5 2 4 3 3 2 3 2 4 3 2 4 -25 -23 -1 -34 -41 -44 -48 -48 -48 20 3 2 2 3 4 1 3 4 3 5 5 1 2 5 2 -22 -22 -1 -33 -42 20 1 5 5 1 5 5 1 2 5 1 5 2 1 4 2 -21 -3 -21 -31 -38 23 4 5 3 4 4 1 5 2 2 5 1 1 2 4 5 -24 -24 -1 -33 -42 -47 ...
result:
ok correct (1000 test cases)
Test #6:
score: 0
Accepted
time: 10ms
memory: 3864kb
input:
1000 99001 99002 99003 99004 99005 99006 99007 99008 99009 99010 99011 99012 99013 99014 99015 99016 99017 99018 99019 99020 99021 99022 99023 99024 99025 99026 99027 99028 99029 99030 99031 99032 99033 99034 99035 99036 99037 99038 99039 99040 99041 99042 99043 99044 99045 99046 99047 99048 99049 9...
output:
29 2 4 5 5 2 4 3 3 2 3 2 4 3 2 4 -25 -23 -1 -1 -1 -1 -5 -38 -41 -45 -46 -47 -47 -48 29 3 2 2 3 4 1 3 4 3 5 5 1 2 5 2 -22 -22 -1 -1 -1 -1 -6 -39 -41 -44 -44 -45 -45 -45 25 3 5 1 4 4 5 1 3 4 3 5 1 4 5 2 -25 -25 -1 -1 -1 -1 -4 -42 -44 -49 28 1 2 1 3 3 5 4 3 5 4 3 2 5 3 5 -25 -24 -1 -1 -1 -1 -5 -37 -...
result:
ok correct (1000 test cases)
Test #7:
score: 0
Accepted
time: 351ms
memory: 3928kb
input:
1000 998001 998002 998003 998004 998005 998006 998007 998008 998009 998010 998011 998012 998013 998014 998015 998016 998017 998018 998019 998020 998021 998022 998023 998024 998025 998026 998027 998028 998029 998030 998031 998032 998033 998034 998035 998036 998037 998038 998039 998040 998041 998042 9...
output:
30 3 3 1 4 3 5 4 2 4 3 4 2 4 2 3 -24 -23 -1 -1 -1 -1 -1 -1 -1 -1 -30 -39 -46 -47 -47 29 3 1 4 4 4 4 5 1 5 1 2 5 5 1 4 -25 -24 -1 -1 -1 -1 -1 -1 -1 -1 -31 -37 -45 -48 30 2 2 4 5 3 4 2 2 4 1 3 4 3 2 3 -22 -22 -1 -1 -1 -1 -1 -1 -1 -1 -29 -38 -39 -41 -42 28 5 1 1 3 1 1 1 4 4 5 4 5 2 1 1 -20 -19 -1 -1...
result:
ok correct (1000 test cases)
Test #8:
score: 0
Accepted
time: 340ms
memory: 4056kb
input:
1000 999001 999002 999003 999004 999005 999006 999007 999008 999009 999010 999011 999012 999013 999014 999015 999016 999017 999018 999019 999020 999021 999022 999023 999024 999025 999026 999027 999028 999029 999030 999031 999032 999033 999034 999035 999036 999037 999038 999039 999040 999041 999042 9...
output:
29 4 3 1 2 4 3 1 4 4 4 5 4 5 4 4 -26 -26 -1 -1 -1 -1 -1 -1 -1 -1 -32 -40 -45 -46 30 4 4 2 5 5 1 3 4 3 1 5 2 5 4 1 -25 -24 -1 -1 -1 -1 -1 -1 -1 -1 -31 -37 -44 -46 -48 30 1 3 3 5 4 3 4 3 1 1 5 3 5 1 3 -22 -22 -1 -1 -1 -1 -1 -1 -1 -1 -30 -39 -43 -45 -45 30 4 3 5 2 2 2 4 4 4 5 1 3 4 4 4 -26 -25 -1 -1...
result:
ok correct (1000 test cases)