QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#329367#1840. K-onstructionHuasushisAC ✓208ms226492kbC++141.3kb2024-02-16 16:36:282024-02-16 16:36:28

Judging History

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

  • [2024-02-16 16:36:28]
  • 评测
  • 测评结果:AC
  • 用时:208ms
  • 内存:226492kb
  • [2024-02-16 16:36:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int m;
#define endl '\n'
#define N 1000010
vector<int> ans[N];
int f[N], g[N][2];
void out(vector<int>& a) {
  cout << a.size() << endl;
  for (auto i : a) {
    cout << i << ' ';
  }
  cout << endl;
}
void gun() {
  cin >> m;
  out(ans[m]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<int> a;
  mt19937 rnd(random_device{}() ^ 19260817);
  int n = 1e6, sum;
  const int orv = 22, fw = 6;
  st:
  a.clear();
  for (int i = 1; i <= orv; ++i) a.emplace_back(rnd() % fw + 1);
  memset(f, 0, sizeof(f));
  memset(g, 0x3f, sizeof(g));
  f[0] = 1;
  g[0][0] = g[0][1] = 0;
  sum = 0;
  for (int i = 0; i < orv; ++i) {
    for (int j = sum; ~j; --j) {
      f[j + a[i]] += f[j];
    }
    sum += a[i];
  }
  for (int i = sum / 2 + 1; i <= sum; ++i) {
    for (int j = f[i]; j <= n; ++j) {
      if (g[j][0] > g[j - f[i]][0] + 1) {
        g[j][0] = g[j - f[i]][0] + 1;
        g[j][1] = i;
      }
    }
  }
  int tot = 0;
  for (int i = 1; i <= n; ++i) {
    if (ans[i].empty() && orv + g[i - 1][0] <= 30) {
      ans[i] = a;
      for (int j = i - 1; j; j -= f[g[j][1]]) {
        ans[i].emplace_back(-g[j][1]);
      }
    }
    tot += ans[i].empty();
  }
  if (tot) goto st;
  int T;
  cin >> T;
  while (T--) {
    gun();
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 180ms
memory: 226260kb

input:

2
3
16

output:

24
5 1 1 5 3 3 6 2 4 5 5 1 4 6 2 5 3 6 2 6 3 2 -80 -80 
25
5 1 1 5 3 3 6 2 4 5 5 1 4 6 2 5 3 6 2 6 3 2 -80 -78 -78 

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 135ms
memory: 226220kb

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:

22
1 4 5 6 3 5 1 4 3 1 5 4 2 2 2 1 2 4 2 1 5 6 
23
1 4 5 6 3 5 1 4 3 1 5 4 2 2 2 1 2 4 2 1 5 6 -69 
24
1 4 5 6 3 5 1 4 3 1 5 4 2 2 2 1 2 4 2 1 5 6 -69 -69 
25
1 4 5 6 3 5 1 4 3 1 5 4 2 2 2 1 2 4 2 1 5 6 -69 -69 -69 
26
1 4 5 6 3 5 1 4 3 1 5 4 2 2 2 1 2 4 2 1 5 6 -69 -69 -69 -69 
23
1 4 5 6 3 5 1 4 3...

result:

ok correct (1000 test cases)

Test #3:

score: 0
Accepted
time: 208ms
memory: 226236kb

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:

26
6 1 2 3 2 2 6 5 2 6 5 5 6 6 3 4 5 5 1 1 3 5 -82 -81 -79 -73 
27
6 1 2 3 2 2 6 5 2 6 5 5 6 6 3 4 5 5 1 1 3 5 -81 -81 -81 -80 -73 
28
6 1 2 3 2 2 6 5 2 6 5 5 6 6 3 4 5 5 1 1 3 5 -81 -81 -77 -77 -76 -75 
27
6 1 2 3 2 2 6 5 2 6 5 5 6 6 3 4 5 5 1 1 3 5 -79 -78 -78 -77 -74 
27
6 1 2 3 2 2 6 5 2 6 5 5 6...

result:

ok correct (1000 test cases)

Test #4:

score: 0
Accepted
time: 140ms
memory: 226492kb

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:

29
5 1 4 2 5 3 6 2 2 2 6 5 3 4 5 1 3 4 3 3 4 1 -50 -49 -43 -43 -40 -39 -39 
29
5 1 4 2 5 3 6 2 2 2 6 5 3 4 5 1 3 4 3 3 4 1 -55 -48 -47 -44 -41 -40 -38 
29
5 1 4 2 5 3 6 2 2 2 6 5 3 4 5 1 3 4 3 3 4 1 -56 -48 -45 -39 -39 -39 -38 
28
5 1 4 2 5 3 6 2 2 2 6 5 3 4 5 1 3 4 3 3 4 1 -68 -45 -44 -39 -38 -38 
...

result:

ok correct (1000 test cases)

Test #5:

score: 0
Accepted
time: 140ms
memory: 226288kb

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:

26
5 6 1 1 6 4 3 4 2 3 5 3 1 2 2 3 4 4 4 6 6 1 -69 -65 -63 -63 
27
5 6 1 1 6 4 3 4 2 3 5 3 1 2 2 3 4 4 4 6 6 1 -70 -68 -68 -66 -61 
27
5 6 1 1 6 4 3 4 2 3 5 3 1 2 2 3 4 4 4 6 6 1 -72 -70 -69 -65 -61 
26
5 6 1 1 6 4 3 4 2 3 5 3 1 2 2 3 4 4 4 6 6 1 -73 -68 -65 -61 
27
5 6 1 1 6 4 3 4 2 3 5 3 1 2 2 3 4...

result:

ok correct (1000 test cases)

Test #6:

score: 0
Accepted
time: 167ms
memory: 226264kb

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:

27
2 3 4 5 6 6 5 3 4 3 1 2 5 3 5 4 5 6 4 3 3 6 -80 -78 -76 -70 -55 
27
2 3 4 5 6 6 5 3 4 3 1 2 5 3 5 4 5 6 4 3 3 6 -74 -67 -67 -65 -59 
28
2 3 4 5 6 6 5 3 4 3 1 2 5 3 5 4 5 6 4 3 3 6 -76 -73 -72 -70 -70 -56 
27
2 3 4 5 6 6 5 3 4 3 1 2 5 3 5 4 5 6 4 3 3 6 -84 -70 -66 -66 -58 
27
2 3 4 5 6 6 5 3 4 3 1...

result:

ok correct (1000 test cases)

Test #7:

score: 0
Accepted
time: 144ms
memory: 226276kb

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:

29
4 3 3 1 2 3 5 3 5 6 5 3 2 2 3 4 2 6 5 1 4 3 -52 -47 -43 -43 -41 -41 -41 
29
4 3 3 1 2 3 5 3 5 6 5 3 2 2 3 4 2 6 5 1 4 3 -56 -47 -42 -42 -42 -40 -39 
29
4 3 3 1 2 3 5 3 5 6 5 3 2 2 3 4 2 6 5 1 4 3 -51 -45 -43 -43 -43 -42 -42 
29
4 3 3 1 2 3 5 3 5 6 5 3 2 2 3 4 2 6 5 1 4 3 -48 -48 -46 -42 -42 -42 -...

result:

ok correct (1000 test cases)

Test #8:

score: 0
Accepted
time: 145ms
memory: 226228kb

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
6 5 2 5 2 1 3 2 3 6 3 5 1 2 3 5 6 2 2 2 5 3 -66 -45 -42 -40 -40 -40 -40 
30
6 5 2 5 2 1 3 2 3 6 3 5 1 2 3 5 6 2 2 2 5 3 -54 -54 -50 -41 -41 -41 -39 -39 
30
6 5 2 5 2 1 3 2 3 6 3 5 1 2 3 5 6 2 2 2 5 3 -55 -55 -45 -44 -42 -42 -40 -38 
29
6 5 2 5 2 1 3 2 3 6 3 5 1 2 3 5 6 2 2 2 5 3 -51 -47 -45 -41 -...

result:

ok correct (1000 test cases)