QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708915#1840. K-onstructionship2077AC ✓16ms3968kbC++231012b2024-11-04 09:31:042024-11-04 09:31:04

Judging History

你现在查看的是最新测评结果

  • [2024-11-04 09:31:04]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:3968kb
  • [2024-11-04 09:31:04]
  • 提交

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;}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3956kb

input:

2
3
16

output:

26
5 3 2 4 2 1 2 3 3 4 3 5 2 4 3 2 2 4 1 5 1 2 3 4 -70 -70
27
2 3 3 5 4 2 4 3 1 1 5 4 5 4 1 4 2 4 5 4 3 4 2 5 -78 -78 -80

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 3968kb

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:

24
5 3 2 4 2 1 2 3 3 4 3 5 2 4 3 2 2 4 1 5 1 2 3 4
25
2 3 3 5 4 2 4 3 1 1 5 4 5 4 1 4 2 4 5 4 3 4 2 5 -80
26
1 1 3 4 4 2 2 1 5 2 2 1 2 4 5 5 2 1 2 2 4 5 3 3 -66 -66
27
2 1 1 4 5 4 1 5 3 3 4 1 5 3 3 3 4 2 4 5 3 4 5 5 -80 -80 -80
26
2 5 2 5 3 4 4 4 4 2 5 5 3 3 1 2 5 3 4 2 5 1 2 3 -78 -78
26
3 1 2 5 4 ...

result:

ok correct (1000 test cases)

Test #3:

score: 0
Accepted
time: 4ms
memory: 3900kb

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:

30
5 4 3 4 5 2 5 2 3 1 3 5 5 2 1 2 5 5 3 5 4 1 5 1 -73 -74 -78 -79 -80 -81
29
2 4 5 2 4 5 5 5 2 4 4 5 3 5 3 1 3 2 4 5 2 5 2 5 -77 -80 -82 -83 -84
29
5 3 5 2 2 1 2 5 3 5 2 4 2 3 4 2 4 4 5 5 1 5 3 1 -70 -72 -73 -76 -77
29
4 1 1 5 5 5 1 4 5 3 5 3 2 3 4 4 1 2 5 1 3 3 5 5 -72 -74 -75 -79 -80
29
4 3 1 1 5...

result:

ok correct (1000 test cases)

Test #4:

score: 0
Accepted
time: 14ms
memory: 3860kb

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 1 4 1 3 2 1 1 2 5 4 2 5 5 4 2 2 5 2 4 5 3 3 4 -38 -51 -63 -68 -69 -73
29
1 2 3 1 2 1 2 3 5 3 2 5 4 3 1 4 2 4 3 1 2 1 2 4 -33 -54 -59 -60 -61
29
4 4 1 3 5 4 5 1 1 1 3 3 1 2 3 2 1 1 1 4 1 2 1 2 -29 -53 -56 -56 -56
29
3 1 5 5 3 5 3 4 4 1 4 5 3 4 3 4 2 2 4 3 1 1 2 1 -37 -58 -69 -70 -70
27
4 5 1 2 3...

result:

ok correct (1000 test cases)

Test #5:

score: 0
Accepted
time: 5ms
memory: 3836kb

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:

29
4 4 1 5 4 3 2 1 5 5 1 4 3 5 2 3 5 1 1 3 5 1 1 1 -59 -67 -68 -68 -69
30
3 3 5 1 2 1 4 1 2 1 3 5 5 5 1 3 5 5 4 4 5 3 4 2 -64 -71 -73 -75 -75 -77
27
1 3 4 2 4 5 1 2 3 3 1 5 5 3 2 3 5 5 4 1 3 2 2 4 -61 -65 -66
29
4 5 5 1 1 2 2 3 5 1 2 3 5 2 5 2 2 4 5 4 4 5 3 4 -66 -69 -71 -79 -79
30
5 2 1 4 1 1 3 5 4...

result:

ok correct (1000 test cases)

Test #6:

score: 0
Accepted
time: 7ms
memory: 3900kb

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:

28
2 2 1 5 5 2 2 1 2 2 3 4 3 3 3 4 2 3 1 1 4 5 3 2 -48 -59 -65 -65
29
5 3 1 1 4 3 3 5 2 1 1 3 4 5 2 3 1 3 2 2 2 1 5 1 -47 -59 -61 -63 -63
28
5 3 4 5 4 1 2 2 4 4 4 1 2 4 3 5 5 4 4 4 5 3 4 3 -61 -73 -83 -85
27
3 2 5 4 1 4 4 5 5 2 5 4 3 3 1 5 1 5 5 4 1 1 2 4 -58 -65 -72
30
4 3 5 5 3 3 2 5 4 3 3 5 1 2 4...

result:

ok correct (1000 test cases)

Test #7:

score: 0
Accepted
time: 16ms
memory: 3836kb

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
5 1 5 4 1 3 4 5 1 2 4 3 5 1 1 5 1 3 5 3 5 3 4 5 -40 -53 -65 -68 -70 -77
29
4 3 3 3 2 3 4 1 4 4 4 2 4 4 3 4 5 2 3 1 3 2 3 4 -38 -52 -61 -72 -72
30
3 5 4 1 4 4 4 3 2 1 4 1 5 5 3 4 3 1 4 3 3 2 5 3 -39 -53 -60 -67 -71 -77
30
2 3 1 4 4 5 5 1 4 5 1 2 5 4 5 2 5 3 4 5 5 3 1 3 -42 -54 -69 -73 -80 -81
29
2...

result:

ok correct (1000 test cases)

Test #8:

score: 0
Accepted
time: 16ms
memory: 3900kb

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 5 3 1 2 4 1 5 3 3 2 3 3 2 2 2 3 3 3 4 1 4 3 1 -34 -49 -56 -60 -67
30
5 1 1 4 3 2 5 1 5 4 5 5 5 2 5 1 3 2 3 3 3 3 5 5 -41 -54 -65 -69 -76 -78
30
4 4 5 3 4 2 1 2 4 5 2 3 4 4 4 4 1 1 5 5 4 4 5 1 -41 -54 -65 -77 -77 -80
30
1 2 5 1 1 5 2 1 4 3 4 4 5 2 2 4 3 1 2 2 2 4 2 3 -33 -48 -55 -57 -60 -61
30
2...

result:

ok correct (1000 test cases)