QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133822#3269. 末日魔法少女计划zhouhuanyi24.980521 27ms4100kbC++232.3kb2023-08-02 14:43:042023-08-02 14:43:07

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 14:43:07]
  • 评测
  • 测评结果:24.980521
  • 用时:27ms
  • 内存:4100kb
  • [2023-08-02 14:43:04]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define N 3000
#define M 20
#define K 100000
#define inf 1e9
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,F[N+1],F2[N+1],dp[M+1][N+1],ps[M+1][N+1];
void adder(int x,int y)
{
	tong[++length]=(reads){x-1,y-1};
	return;
}
void solve(int l,int r)
{
	if (r-l<=k) return;
	int res=r-l+1;
	vector<int>s(n+2);
	vector<int>used(n+2);
	vector<int>p(k);
	for (int i=k;i>=1;--i)
	{
		res=ps[i][res];
		if (i!=1) p[i-1]=res+l,s[p[i-1]]=used[p[i-1]]=1;
	}
	for (int i=l;i<=r;++i) s[i]+=s[i-1];
	for (int i=1;i<=k-2;++i)
		if (p[i+1]-p[i]>1)
			adder(p[i],p[i+1]);
	for (int i=l;i<=r;++i)
		if (!used[i])
		{
			if (s[i]&&i-p[s[i]]>1) adder(p[s[i]],i);
			if (s[i]!=k-1&&p[s[i]+1]-i>1) adder(i,p[s[i]+1]);
		}
	if (l<=p[1]-1) solve(l,p[1]-1);
	for (int i=1;i<=k-2;++i)
		if (p[i]+1<=p[i+1]-1)
			solve(p[i]+1,p[i+1]-1);
	if (p[k-1]+1<=r) solve(p[k-1]+1,r);
	return;
}
int main()
{
	n=read(),k=read();
	for (int i=1;i<=k;++i)
		for (int j=0;j<=n+1;++j)
			dp[i][j]=inf;
	for (int i=0;i<=n;++i) F[i]=max(i-1,0),F2[i]=max(i-1,0)<<1;
	for (int i=1;i<=n+1;++i)
	{
		if (i<=k+1) dp[1][i]=0;
		else
		{
			for (int j=2;j<=k;++j)
			{
				if (j==2)
				{
					if (k==2)
					{
						for (int t=0;t<=i-1;++t)
							if (dp[j-1][t]+dp[1][i-1-t]+F[t]+F[i-1-t]<dp[j][i])
								dp[j][i]=dp[j-1][t]+dp[1][i-1-t]+F[t]+F[i-1-t],ps[j][i]=t;
					}
					else
					{
						for (int t=0;t<=i-1;++t)
							if (dp[j-1][t]+dp[1][i-1-t]+F[t]+F2[i-1-t]<dp[j][i])
								dp[j][i]=dp[j-1][t]+dp[1][i-1-t]+F[t]+F2[i-1-t],ps[j][i]=t;
					}
				}
				else if (j==k)
				{
					for (int t=0;t<=i-1;++t)
						if (dp[j-1][t]+dp[1][i-1-t]+F[i-1-t]+(t!=i-1)<dp[j][i])
							dp[j][i]=dp[j-1][t]+dp[1][i-1-t]+F[i-1-t]+(t!=i-1),ps[j][i]=t;
				}
				else
				{
					for (int t=0;t<=i-1;++t)
						if (dp[j-1][t]+dp[1][i-1-t]+F2[i-1-t]+(t!=i-1)<dp[j][i])
							dp[j][i]=dp[j-1][t]+dp[1][i-1-t]+F2[i-1-t]+(t!=i-1),ps[j][i]=t;
				}
			}
			dp[1][i]=dp[k][i];
		}
	}
	solve(1,n+1),printf("%d\n",length);
	for (int i=1;i<=length;++i) printf("%d %d\n",tong[i].x,tong[i].y);
	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: 3956kb

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: 3960kb

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: 4ms
memory: 3960kb

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: 2ms
memory: 3952kb

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: 4ms
memory: 3976kb

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: 2.98052
Acceptable Answer

Test #6:

score: 3.04494
Acceptable Answer
time: 6ms
memory: 3940kb

input:

1936 3

output:

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

result:

points 0.21749538370

Test #7:

score: 2.98052
Acceptable Answer
time: 6ms
memory: 3924kb

input:

2000 3

output:

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

result:

points 0.21289438440

Test #8:

score: 2.98149
Acceptable Answer
time: 6ms
memory: 3992kb

input:

1999 3

output:

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

result:

points 0.21296380890

Test #9:

score: 2.98833
Acceptable Answer
time: 3ms
memory: 3924kb

input:

1992 3

output:

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

result:

points 0.21345190490

Test #10:

score: 3.00714
Acceptable Answer
time: 6ms
memory: 4000kb

input:

1973 3

output:

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

result:

points 0.214795760

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 8ms
memory: 3928kb

input:

2000 4

output:

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

result:

wrong answer 

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 6ms
memory: 3992kb

input:

2000 5

output:

9555
546 728
728 910
910 1092
0 546
1 546
2 546
3 546
4 546
5 546
6 546
7 546
8 546
9 546
10 546
11 546
12 546
13 546
14 546
15 546
16 546
17 546
18 546
19 546
20 546
21 546
22 546
23 546
24 546
25 546
26 546
27 546
28 546
29 546
30 546
31 546
32 546
33 546
34 546
35 546
36 546
37 546
38 546
39 546
...

result:

wrong answer 

Subtask #5:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 11ms
memory: 3940kb

input:

2000 6

output:

8810
255 401
401 657
657 913
913 1169
0 255
1 255
2 255
3 255
4 255
5 255
6 255
7 255
8 255
9 255
10 255
11 255
12 255
13 255
14 255
15 255
16 255
17 255
18 255
19 255
20 255
21 255
22 255
23 255
24 255
25 255
26 255
27 255
28 255
29 255
30 255
31 255
32 255
33 255
34 255
35 255
36 255
37 255
38 255...

result:

wrong answer 

Subtask #6:

score: 0
Wrong Answer

Test #26:

score: 0
Wrong Answer
time: 13ms
memory: 3972kb

input:

1999 7

output:

8336
341 442
442 543
543 644
644 745
745 846
0 341
1 341
2 341
3 341
4 341
5 341
6 341
7 341
8 341
9 341
10 341
11 341
12 341
13 341
14 341
15 341
16 341
17 341
18 341
19 341
20 341
21 341
22 341
23 341
24 341
25 341
26 341
27 341
28 341
29 341
30 341
31 341
32 341
33 341
34 341
35 341
36 341
37 341...

result:

wrong answer 

Subtask #7:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 15ms
memory: 3992kb

input:

1995 8

output:

7755
439 563
563 687
687 811
811 935
935 1059
1059 1183
0 439
1 439
2 439
3 439
4 439
5 439
6 439
7 439
8 439
9 439
10 439
11 439
12 439
13 439
14 439
15 439
16 439
17 439
18 439
19 439
20 439
21 439
22 439
23 439
24 439
25 439
26 439
27 439
28 439
29 439
30 439
31 439
32 439
33 439
34 439
35 439
36...

result:

wrong answer 

Subtask #8:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 16ms
memory: 3976kb

input:

1997 9

output:

7250
405 554
554 703
703 852
852 1001
1001 1150
1150 1299
1299 1448
0 405
1 405
2 405
3 405
4 405
5 405
6 405
7 405
8 405
9 405
10 405
11 405
12 405
13 405
14 405
15 405
16 405
17 405
18 405
19 405
20 405
21 405
22 405
23 405
24 405
25 405
26 405
27 405
28 405
29 405
30 405
31 405
32 405
33 405
34 4...

result:

wrong answer 

Subtask #9:

score: 0
Wrong Answer

Test #41:

score: 0
Wrong Answer
time: 14ms
memory: 3972kb

input:

1995 10

output:

7088
175 215
215 268
268 444
444 620
620 796
796 972
972 1148
1148 1324
0 175
1 175
2 175
3 175
4 175
5 175
6 175
7 175
8 175
9 175
10 175
11 175
12 175
13 175
14 175
15 175
16 175
17 175
18 175
19 175
20 175
21 175
22 175
23 175
24 175
25 175
26 175
27 175
28 175
29 175
30 175
31 175
32 175
33 175
...

result:

wrong answer 

Subtask #10:

score: 0
Wrong Answer

Test #46:

score: 0
Wrong Answer
time: 16ms
memory: 4016kb

input:

1993 11

output:

6912
204 248
248 292
292 336
336 380
380 424
424 573
573 778
778 983
983 1188
0 204
1 204
2 204
3 204
4 204
5 204
6 204
7 204
8 204
9 204
10 204
11 204
12 204
13 204
14 204
15 204
16 204
17 204
18 204
19 204
20 204
21 204
22 204
23 204
24 204
25 204
26 204
27 204
28 204
29 204
30 204
31 204
32 204
3...

result:

wrong answer 

Subtask #11:

score: 0
Wrong Answer

Test #51:

score: 0
Wrong Answer
time: 22ms
memory: 4052kb

input:

1999 12

output:

6754
235 283
283 331
331 379
379 427
427 475
475 523
523 571
571 619
619 812
812 1048
0 235
1 235
2 235
3 235
4 235
5 235
6 235
7 235
8 235
9 235
10 235
11 235
12 235
13 235
14 235
15 235
16 235
17 235
18 235
19 235
20 235
21 235
22 235
23 235
24 235
25 235
26 235
27 235
28 235
29 235
30 235
31 235
...

result:

wrong answer 

Subtask #12:

score: 0
Wrong Answer

Test #56:

score: 0
Wrong Answer
time: 23ms
memory: 4064kb

input:

1981 13

output:

6486
268 320
320 372
372 424
424 476
476 528
528 580
580 632
632 684
684 736
736 788
788 872
0 268
1 268
2 268
3 268
4 268
5 268
6 268
7 268
8 268
9 268
10 268
11 268
12 268
13 268
14 268
15 268
16 268
17 268
18 268
19 268
20 268
21 268
22 268
23 268
24 268
25 268
26 268
27 268
28 268
29 268
30 268
...

result:

wrong answer 

Subtask #13:

score: 0
Wrong Answer

Test #61:

score: 0
Wrong Answer
time: 25ms
memory: 4096kb

input:

1979 14

output:

6268
303 359
359 415
415 471
471 527
527 583
583 639
639 695
695 751
751 807
807 863
863 919
919 975
0 303
1 303
2 303
3 303
4 303
5 303
6 303
7 303
8 303
9 303
10 303
11 303
12 303
13 303
14 303
15 303
16 303
17 303
18 303
19 303
20 303
21 303
22 303
23 303
24 303
25 303
26 303
27 303
28 303
29 303...

result:

wrong answer 

Subtask #14:

score: 0
Wrong Answer

Test #66:

score: 0
Wrong Answer
time: 27ms
memory: 4100kb

input:

2000 15

output:

6128
340 400
400 460
460 520
520 580
580 640
640 700
700 760
760 820
820 880
880 940
940 1000
1000 1060
1060 1120
0 340
1 340
2 340
3 340
4 340
5 340
6 340
7 340
8 340
9 340
10 340
11 340
12 340
13 340
14 340
15 340
16 340
17 340
18 340
19 340
20 340
21 340
22 340
23 340
24 340
25 340
26 340
27 340
...

result:

wrong answer