QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134069#3269. 末日魔法少女计划zhouhuanyi63 1202ms97688kbC++233.3kb2023-08-02 22:39:222023-08-02 22:39:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 22:39:25]
  • 评测
  • 测评结果:63
  • 用时:1202ms
  • 内存:97688kb
  • [2023-08-02 22:39:22]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#define N 2001
#define M 15
#define K 100000
#define W 992
#define inf 1e8
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	int x,y;
};
reads tong[K+1];
int n,k,length,dp[M+1][W+1][N+1],ps[M+1][W+1][N+1],ps2[M+1][W+1][N+1],pst[M+1][W+1][N+1],F[N+1],F2[N+1],maxn[M+1]={0,0,0,31,320,276,992,992,991,990,989,988,987,986,985,984};
void adder(int x,int y)
{
	tong[++length]=(reads){x,y};
	return;
}
void calc()
{
	for (int i=1;i<=n;++i) F[i]=i-1,F2[i]=(i-1)<<1;
	for (int i=0;i<=k;++i)
		for (int j=0;j<=min(W,n);++j)
			for (int t=0;t<=n;++t)
				dp[i][j][t]=inf;
	dp[0][0][0]=dp[0][0][1]=dp[1][0][0]=0;
	for (int i=1;i<=n;++i) dp[1][0][i]=((i*(i-1))>>1)-(i-1);
	for (int i=2;i<=k;++i)
		for (int j=0;j<=n;++j)
		{
			if (j<=i+1) dp[i][0][j]=0;
			for (int s=1;s<=min(maxn[i],j-1);++s)
			{
				if (s==1)
				{
					for (int t=(j?ps[i][s][j-1]:0);t<=j-1;++t)
						if (dp[i][0][t]+dp[i][0][j-1-t]+F[t]+F2[j-1-t]+(t!=j-1)<dp[i][s][j])
							dp[i][s][j]=dp[i][0][t]+dp[i][0][j-1-t]+F[t]+F2[j-1-t]+(t!=j-1),ps[i][s][j]=t;
				}
				else
				{
					for (int t=(j?ps[i][s][j-1]:0);t<=j-1;++t)
						if (dp[i][s-1][t]+dp[i][0][j-1-t]+F2[j-1-t]+(t!=j-1)<dp[i][s][j])
							dp[i][s][j]=dp[i][s-1][t]+dp[i][0][j-1-t]+F2[j-1-t]+(t!=j-1),ps[i][s][j]=t;
				}
				if (j!=i-1)
				{
					for (int t=(j?pst[i][s][j-1]:0);t<=j-1;++t)
						if (dp[i][s][t]+dp[i][0][j-1-t]+F[j-1-t]+dp[i-2][0][s+1]<dp[i][0][j])
							dp[i][0][j]=dp[i][s][t]+dp[i][0][j-1-t]+F[j-1-t]+dp[i-2][0][s+1],ps[i][0][j]=pst[i][s][j]=t,ps2[i][0][j]=s;
				}
			}
			for (int t=0;t<=j-1;++t)
				if (dp[i][0][t]+dp[i][0][j-1-t]+F[t]+F[j-1-t]<dp[i][0][j])
					dp[i][0][j]=dp[i][0][t]+dp[i][0][j-1-t]+F[t]+F[j-1-t],ps[i][0][j]=t,ps2[i][0][j]=0;
		}
	return;
}
void solve(vector<int>p,int d)
{
	if (p.size()<=d+1) return;
	if (d==1)
	{
		for (int i=0;i<p.size();++i)
			for (int j=i+2;j<p.size();++j)
				adder(p[i],p[j]);
	}
	else
	{
		int r=ps2[d][0][p.size()]+1,pst;
		vector<int>v(r+1);
		vector<int>st;
		pst=ps[d][0][p.size()],v[r]=pst+1;
		for (int i=r-1;i>=1;--i) v[i]=ps[d][i][pst]+1,pst=ps[d][i][pst];
		for (int i=1;i<=r-1;++i)
			if (v[i+1]-v[i]!=1)
				adder(p[v[i]-1],p[v[i+1]-1]);
		for (int i=1;i<=r;++i) st.push_back(p[v[i]-1]);
		solve(st,d-2);
		if (1<=v[1]-1)
		{
			st.clear();
			for (int i=1;i<=v[1]-1;++i)
			{
				if (i!=v[1]-1) adder(p[i-1],p[v[1]-1]);
				st.push_back(p[i-1]);
			}
			solve(st,d);
		}
		for (int i=1;i<=r-1;++i)
			if (v[i]+1<=v[i+1]-1)
			{
				st.clear();
				for (int j=v[i]+1;j<=v[i+1]-1;++j)
				{
					if (j!=v[i]+1) adder(p[v[i]-1],p[j-1]);
					if (j!=v[i+1]-1) adder(p[j-1],p[v[i+1]-1]);
					st.push_back(p[j-1]);
				}
				solve(st,d);
			}
		if (v[r]+1<=p.size())
		{
			st.clear();
			for (int i=v[r]+1;i<=p.size();++i)
			{
				if (i!=v[r]+1) adder(p[v[r]-1],p[i-1]);
				st.push_back(p[i-1]);
			}
			solve(st,d);
		}
	}
	return;
}
int main()
{
	vector<int>p;
	n=read()+1,k=read(),calc();
	for (int i=1;i<=n;++i) p.push_back(i);
	solve(p,k),printf("%d\n",length);
	for (int i=1;i<=length;++i) printf("%d %d\n",tong[i].x-1,tong[i].y-1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 22
Accepted

Test #1:

score: 22
Accepted
time: 1ms
memory: 34420kb

input:

2000 2

output:

15974
0 977
1 977
2 977
3 977
4 977
5 977
6 977
7 977
8 977
9 977
10 977
11 977
12 977
13 977
14 977
15 977
16 977
17 977
18 977
19 977
20 977
21 977
22 977
23 977
24 977
25 977
26 977
27 977
28 977
29 977
30 977
31 977
32 977
33 977
34 977
35 977
36 977
37 977
38 977
39 977
40 977
41 977
42 977
43 ...

result:

ok 

Test #2:

score: 22
Accepted
time: 1ms
memory: 34596kb

input:

1999 2

output:

15965
0 976
1 976
2 976
3 976
4 976
5 976
6 976
7 976
8 976
9 976
10 976
11 976
12 976
13 976
14 976
15 976
16 976
17 976
18 976
19 976
20 976
21 976
22 976
23 976
24 976
25 976
26 976
27 976
28 976
29 976
30 976
31 976
32 976
33 976
34 976
35 976
36 976
37 976
38 976
39 976
40 976
41 976
42 976
43 ...

result:

ok 

Test #3:

score: 22
Accepted
time: 3ms
memory: 36456kb

input:

1992 2

output:

15902
0 969
1 969
2 969
3 969
4 969
5 969
6 969
7 969
8 969
9 969
10 969
11 969
12 969
13 969
14 969
15 969
16 969
17 969
18 969
19 969
20 969
21 969
22 969
23 969
24 969
25 969
26 969
27 969
28 969
29 969
30 969
31 969
32 969
33 969
34 969
35 969
36 969
37 969
38 969
39 969
40 969
41 969
42 969
43 ...

result:

ok 

Test #4:

score: 22
Accepted
time: 5ms
memory: 34408kb

input:

1973 2

output:

15731
0 950
1 950
2 950
3 950
4 950
5 950
6 950
7 950
8 950
9 950
10 950
11 950
12 950
13 950
14 950
15 950
16 950
17 950
18 950
19 950
20 950
21 950
22 950
23 950
24 950
25 950
26 950
27 950
28 950
29 950
30 950
31 950
32 950
33 950
34 950
35 950
36 950
37 950
38 950
39 950
40 950
41 950
42 950
43 ...

result:

ok 

Test #5:

score: 22
Accepted
time: 5ms
memory: 34476kb

input:

1936 2

output:

15398
0 913
1 913
2 913
3 913
4 913
5 913
6 913
7 913
8 913
9 913
10 913
11 913
12 913
13 913
14 913
15 913
16 913
17 913
18 913
19 913
20 913
21 913
22 913
23 913
24 913
25 913
26 913
27 913
28 913
29 913
30 913
31 913
32 913
33 913
34 913
35 913
36 913
37 913
38 913
39 913
40 913
41 913
42 913
43 ...

result:

ok 

Subtask #2:

score: 14
Accepted

Test #6:

score: 14
Accepted
time: 33ms
memory: 45224kb

input:

1936 3

output:

7339
247 295
295 343
343 391
391 439
439 487
487 535
535 583
583 631
631 679
679 727
727 775
775 823
823 871
871 919
919 967
967 1015
1015 1063
1063 1111
1111 1159
1159 1207
1207 1255
1255 1303
1303 1351
1351 1399
1399 1447
1447 1495
1495 1543
1543 1591
1591 1639
1639 1687
247 343
247 391
247 439
24...

result:

ok 

Test #7:

score: 14
Accepted
time: 29ms
memory: 43136kb

input:

2000 3

output:

7605
249 297
297 345
345 393
393 441
441 489
489 537
537 585
585 633
633 681
681 729
729 777
777 825
825 873
873 921
921 969
969 1017
1017 1065
1065 1113
1113 1161
1161 1209
1209 1257
1257 1305
1305 1353
1353 1401
1401 1449
1449 1497
1497 1545
1545 1593
1593 1641
1641 1689
1689 1737
249 345
249 393
...

result:

ok 

Test #8:

score: 14
Accepted
time: 27ms
memory: 47160kb

input:

1999 3

output:

7601
249 297
297 345
345 393
393 441
441 489
489 537
537 585
585 633
633 681
681 729
729 777
777 825
825 873
873 921
921 969
969 1017
1017 1065
1065 1113
1113 1161
1161 1209
1209 1257
1257 1305
1305 1353
1353 1401
1401 1449
1449 1497
1497 1545
1545 1593
1593 1641
1641 1689
1689 1737
249 345
249 393
...

result:

ok 

Test #9:

score: 14
Accepted
time: 27ms
memory: 45104kb

input:

1992 3

output:

7572
249 297
297 345
345 393
393 441
441 489
489 537
537 585
585 633
633 681
681 729
729 777
777 825
825 873
873 921
921 969
969 1017
1017 1065
1065 1113
1113 1161
1161 1209
1209 1257
1257 1305
1305 1353
1353 1401
1401 1449
1449 1497
1497 1545
1545 1593
1593 1641
1641 1689
1689 1737
249 345
249 393
...

result:

ok 

Test #10:

score: 14
Accepted
time: 31ms
memory: 47164kb

input:

1973 3

output:

7493
235 283
283 331
331 379
379 427
427 475
475 523
523 571
571 619
619 667
667 715
715 763
763 811
811 859
859 907
907 955
955 1003
1003 1051
1051 1099
1099 1147
1147 1195
1195 1243
1243 1291
1291 1339
1339 1387
1387 1435
1435 1483
1483 1531
1531 1579
1579 1627
1627 1675
1675 1723
235 331
235 379
...

result:

ok 

Subtask #3:

score: 11
Accepted

Test #11:

score: 11
Accepted
time: 258ms
memory: 58112kb

input:

2000 4

output:

4792
39 45
45 51
51 57
57 63
63 69
69 75
75 81
81 87
87 93
93 99
99 105
105 111
111 117
117 123
123 129
129 135
135 141
141 147
147 153
153 159
159 165
165 171
171 177
177 183
183 189
189 195
195 201
201 207
207 213
213 219
219 225
225 231
231 237
237 243
243 249
249 255
255 261
261 267
267 273
273 ...

result:

ok 

Test #12:

score: 11
Accepted
time: 253ms
memory: 58092kb

input:

1999 4

output:

4789
39 45
45 51
51 57
57 63
63 69
69 75
75 81
81 87
87 93
93 99
99 105
105 111
111 117
117 123
123 129
129 135
135 141
141 147
147 153
153 159
159 165
165 171
171 177
177 183
183 189
189 195
195 201
201 207
207 213
213 219
219 225
225 231
231 237
237 243
243 249
249 255
255 261
261 267
267 273
273 ...

result:

ok 

Test #13:

score: 11
Accepted
time: 247ms
memory: 60112kb

input:

1991 4

output:

4768
37 43
43 49
49 55
55 61
61 67
67 73
73 79
79 85
85 91
91 97
97 103
103 109
109 115
115 121
121 127
127 133
133 139
139 145
145 151
151 157
157 163
163 169
169 175
175 181
181 187
187 193
193 199
199 205
205 211
211 217
217 223
223 229
229 235
235 241
241 247
247 253
253 259
259 265
265 271
271 ...

result:

ok 

Test #14:

score: 11
Accepted
time: 243ms
memory: 57984kb

input:

1971 4

output:

4715
39 45
45 51
51 57
57 63
63 69
69 75
75 81
81 87
87 93
93 99
99 105
105 111
111 117
117 123
123 129
129 135
135 141
141 147
147 153
153 159
159 165
165 171
171 177
177 183
183 189
189 195
195 201
201 207
207 213
213 219
219 225
225 231
231 237
237 243
243 249
249 255
255 261
261 267
267 273
273 ...

result:

ok 

Test #15:

score: 11
Accepted
time: 244ms
memory: 60028kb

input:

1938 4

output:

4626
39 45
45 51
51 57
57 63
63 69
69 75
75 81
81 87
87 93
93 99
99 105
105 111
111 117
117 123
123 129
129 135
135 141
141 147
147 153
153 159
159 165
165 171
171 177
177 183
183 189
189 195
195 201
201 207
207 213
213 219
219 225
225 231
231 237
237 243
243 249
249 255
255 261
261 267
267 273
273 ...

result:

ok 

Subtask #4:

score: 9
Accepted

Test #16:

score: 9
Accepted
time: 505ms
memory: 72320kb

input:

2000 5

output:

3922
31 38
38 45
45 52
52 59
59 66
66 73
73 80
80 87
87 94
94 101
101 108
108 115
115 122
122 129
129 136
136 143
143 150
150 157
157 164
164 171
171 178
178 185
185 192
192 199
199 206
206 213
213 220
220 227
227 234
234 241
241 248
248 255
255 262
262 269
269 276
276 283
283 290
290 297
297 304
30...

result:

ok 

Test #17:

score: 9
Accepted
time: 505ms
memory: 72336kb

input:

1999 5

output:

3920
37 44
44 51
51 58
58 65
65 72
72 79
79 86
86 93
93 100
100 107
107 114
114 121
121 128
128 135
135 142
142 149
149 156
156 163
163 170
170 177
177 184
184 191
191 198
198 205
205 212
212 219
219 226
226 233
233 240
240 247
247 254
254 261
261 268
268 275
275 282
282 289
289 296
296 303
303 310
...

result:

ok 

Test #18:

score: 9
Accepted
time: 506ms
memory: 72388kb

input:

1992 5

output:

3905
37 44
44 51
51 58
58 65
65 72
72 79
79 86
86 93
93 100
100 107
107 114
114 121
121 128
128 135
135 142
142 149
149 156
156 163
163 170
170 177
177 184
184 191
191 198
198 205
205 212
212 219
219 226
226 233
233 240
240 247
247 254
254 261
261 268
268 275
275 282
282 289
289 296
296 303
303 310
...

result:

ok 

Test #19:

score: 9
Accepted
time: 505ms
memory: 74448kb

input:

1973 5

output:

3866
32 39
39 46
46 53
53 60
60 67
67 74
74 81
81 88
88 95
95 102
102 109
109 116
116 123
123 130
130 137
137 144
144 151
151 158
158 165
165 172
172 179
179 186
186 193
193 200
200 207
207 214
214 221
221 228
228 235
235 242
242 249
249 256
256 263
263 270
270 277
277 284
284 291
291 298
298 305
30...

result:

ok 

Test #20:

score: 9
Accepted
time: 480ms
memory: 72192kb

input:

1936 5

output:

3791
37 44
44 51
51 58
58 65
65 72
72 79
79 86
86 93
93 100
100 107
107 114
114 121
121 128
128 135
135 142
142 149
149 156
156 163
163 170
170 177
177 184
184 191
191 198
198 205
205 212
212 219
219 226
226 233
233 240
240 247
247 254
254 261
261 268
268 275
275 282
282 289
289 296
296 303
303 310
...

result:

ok 

Subtask #5:

score: 7
Accepted

Test #21:

score: 7
Accepted
time: 1192ms
memory: 95676kb

input:

2000 6

output:

3213
7 9
9 11
11 13
13 15
15 17
17 19
19 21
21 23
23 25
25 27
27 29
29 31
31 33
33 35
35 37
37 39
39 41
41 43
43 45
45 47
47 49
49 51
51 53
53 55
55 57
57 59
59 61
61 63
63 65
65 67
67 69
69 71
71 73
73 75
75 77
77 79
79 81
81 83
83 85
85 87
87 89
89 91
91 93
93 95
95 97
97 99
99 101
101 103
103 105...

result:

ok 

Test #22:

score: 7
Accepted
time: 1202ms
memory: 95632kb

input:

1997 6

output:

3208
7 9
9 11
11 13
13 15
15 17
17 19
19 21
21 23
23 25
25 27
27 29
29 31
31 33
33 35
35 37
37 39
39 41
41 43
43 45
45 47
47 49
49 51
51 53
53 55
55 57
57 59
59 61
61 63
63 65
65 67
67 69
69 71
71 73
73 75
75 77
77 79
79 81
81 83
83 85
85 87
87 89
89 91
91 93
93 95
95 97
97 99
99 101
101 103
103 105...

result:

ok 

Test #23:

score: 7
Accepted
time: 1186ms
memory: 97688kb

input:

1989 6

output:

3194
7 9
9 11
11 13
13 15
15 17
17 19
19 21
21 23
23 25
25 27
27 29
29 31
31 33
33 35
35 37
37 39
39 41
41 43
43 45
45 47
47 49
49 51
51 53
53 55
55 57
57 59
59 61
61 63
63 65
65 67
67 69
69 71
71 73
73 75
75 77
77 79
79 81
81 83
83 85
85 87
87 89
89 91
91 93
93 95
95 97
97 99
99 101
101 103
103 105...

result:

ok 

Test #24:

score: 7
Accepted
time: 1175ms
memory: 95512kb

input:

1972 6

output:

3164
7 9
9 11
11 13
13 15
15 17
17 19
19 21
21 23
23 25
25 27
27 29
29 31
31 33
33 35
35 37
37 39
39 41
41 43
43 45
45 47
47 49
49 51
51 53
53 55
55 57
57 59
59 61
61 63
63 65
65 67
67 69
69 71
71 73
73 75
75 77
77 79
79 81
81 83
83 85
85 87
87 89
89 91
91 93
93 95
95 97
97 99
99 101
101 103
103 105...

result:

ok 

Test #25:

score: 7
Accepted
time: 1137ms
memory: 93288kb

input:

1933 6

output:

3096
7 9
9 11
11 13
13 15
15 17
17 19
19 21
21 23
23 25
25 27
27 29
29 31
31 33
33 35
35 37
37 39
39 41
41 43
43 45
45 47
47 49
49 51
51 53
53 55
55 57
57 59
59 61
61 63
63 65
65 67
67 69
69 71
71 73
73 75
75 77
77 79
79 81
81 83
83 85
85 87
87 89
89 91
91 93
93 95
95 97
97 99
99 101
101 103
103 105...

result:

ok 

Subtask #6:

score: 0
Time Limit Exceeded

Test #26:

score: 0
Time Limit Exceeded

input:

1999 7

output:


result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

1995 8

output:


result:


Subtask #8:

score: 0
Time Limit Exceeded

Test #36:

score: 0
Time Limit Exceeded

input:

1997 9

output:


result:


Subtask #9:

score: 0
Time Limit Exceeded

Test #41:

score: 0
Time Limit Exceeded

input:

1995 10

output:


result:


Subtask #10:

score: 0
Time Limit Exceeded

Test #46:

score: 0
Time Limit Exceeded

input:

1993 11

output:


result:


Subtask #11:

score: 0
Time Limit Exceeded

Test #51:

score: 0
Time Limit Exceeded

input:

1999 12

output:


result:


Subtask #12:

score: 0
Time Limit Exceeded

Test #56:

score: 0
Time Limit Exceeded

input:

1981 13

output:


result:


Subtask #13:

score: 0
Time Limit Exceeded

Test #61:

score: 0
Time Limit Exceeded

input:

1979 14

output:


result:


Subtask #14:

score: 0
Time Limit Exceeded

Test #66:

score: 0
Time Limit Exceeded

input:

2000 15

output:


result: