Submission #207758

# Submission time Handle Problem Language Result Execution time Memory
207758 2020-03-08T20:38:47 Z super_j6 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
101 ms 128796 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second

const long long inf = 1000000000000000007;
const int maxn = 202;
int n, m;
pi a[maxn];
long long dp[maxn][maxn][maxn][2];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++) cin >> a[i].f;
	for(int i = 1; i <= n; i++) cin >> a[i].s;
	a[n + 1].f = m;
	sort(a + 1, a + n + 1);
	
	for(int i = 0; i <= n; i++)
	for(int j = 0; j <= n; j++)
	for(int k = n + 1; k > j; k--) dp[i][j][k][0] = dp[i][j][k][1] = inf;
	
	int ret = 0;
	dp[0][0][n + 1][0] = dp[0][0][n + 1][1] = 0;
	for(int i = 0; i <= n; i++)
	for(int j = 0; j <= n; j++)
	for(int k = n + 1; k > j; k--){
		long long x;
		if(dp[i][j][k][0] != inf){
			ret = i;
			x = dp[i][j][k][0] + a[j + 1].f - a[j].f;
			dp[i][j + 1][k][0] = min(dp[i][j + 1][k][0], x);
			if(x <= a[j + 1].s) dp[i + 1][j + 1][k][0] = min(dp[i + 1][j + 1][k][0], x);
			x = dp[i][j][k][0] + a[j].f + m - a[k - 1].f;
			dp[i][j][k - 1][1] = min(dp[i][j][k - 1][1], x);
			if(x <= a[k - 1].s) dp[i + 1][j][k - 1][1] = min(dp[i + 1][j][k - 1][1], x);
		}
		if(dp[i][j][k][1] != inf){
			ret = i;
			x = dp[i][j][k][1] + a[k].f - a[k - 1].f;
			dp[i][j][k - 1][1] = min(dp[i][j][k - 1][1], x);
			if(x <= a[k - 1].s) dp[i + 1][j][k - 1][1] = min(dp[i + 1][j][k - 1][1], x);
			x = dp[i][j][k][1] + a[j + 1].f + m - a[k].f;
			dp[i][j + 1][k][0] = min(dp[i][j + 1][k][0], x);
			if(x <= a[j + 1].s) dp[i + 1][j + 1][k][0] = min(dp[i + 1][j + 1][k][0], x);
		}
	}
	
	cout << ret << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 888 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 552 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 5 ms 1064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 888 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 552 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 5 ms 1064 KB Output is correct
18 Correct 5 ms 1144 KB Output is correct
19 Correct 5 ms 764 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 5 ms 1144 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 1144 KB Output is correct
24 Correct 5 ms 1020 KB Output is correct
25 Correct 5 ms 1144 KB Output is correct
26 Correct 5 ms 1144 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 5 ms 1272 KB Output is correct
30 Correct 5 ms 1272 KB Output is correct
31 Correct 5 ms 1016 KB Output is correct
32 Correct 5 ms 1016 KB Output is correct
33 Correct 6 ms 1272 KB Output is correct
34 Correct 5 ms 1272 KB Output is correct
35 Correct 5 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 888 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 552 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 5 ms 1064 KB Output is correct
18 Correct 71 ms 103928 KB Output is correct
19 Correct 46 ms 63096 KB Output is correct
20 Correct 24 ms 33788 KB Output is correct
21 Correct 39 ms 59512 KB Output is correct
22 Correct 52 ms 77176 KB Output is correct
23 Correct 22 ms 28792 KB Output is correct
24 Correct 19 ms 22648 KB Output is correct
25 Correct 22 ms 28280 KB Output is correct
26 Correct 10 ms 10744 KB Output is correct
27 Correct 23 ms 29432 KB Output is correct
28 Correct 15 ms 20984 KB Output is correct
29 Correct 22 ms 29944 KB Output is correct
30 Correct 17 ms 23416 KB Output is correct
31 Correct 21 ms 28152 KB Output is correct
32 Correct 12 ms 14840 KB Output is correct
33 Correct 20 ms 28152 KB Output is correct
34 Correct 9 ms 9976 KB Output is correct
35 Correct 19 ms 27384 KB Output is correct
36 Correct 11 ms 13048 KB Output is correct
37 Correct 20 ms 29176 KB Output is correct
38 Correct 13 ms 16120 KB Output is correct
39 Correct 21 ms 30456 KB Output is correct
40 Correct 15 ms 17912 KB Output is correct
41 Correct 92 ms 127992 KB Output is correct
42 Correct 52 ms 86008 KB Output is correct
43 Correct 93 ms 127992 KB Output is correct
44 Correct 50 ms 84984 KB Output is correct
45 Correct 93 ms 127992 KB Output is correct
46 Correct 54 ms 86008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 888 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 552 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 5 ms 1064 KB Output is correct
18 Correct 5 ms 1144 KB Output is correct
19 Correct 5 ms 764 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 5 ms 1144 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 1144 KB Output is correct
24 Correct 5 ms 1020 KB Output is correct
25 Correct 5 ms 1144 KB Output is correct
26 Correct 5 ms 1144 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 5 ms 1272 KB Output is correct
30 Correct 5 ms 1272 KB Output is correct
31 Correct 5 ms 1016 KB Output is correct
32 Correct 5 ms 1016 KB Output is correct
33 Correct 6 ms 1272 KB Output is correct
34 Correct 5 ms 1272 KB Output is correct
35 Correct 5 ms 1272 KB Output is correct
36 Correct 71 ms 103928 KB Output is correct
37 Correct 46 ms 63096 KB Output is correct
38 Correct 24 ms 33788 KB Output is correct
39 Correct 39 ms 59512 KB Output is correct
40 Correct 52 ms 77176 KB Output is correct
41 Correct 22 ms 28792 KB Output is correct
42 Correct 19 ms 22648 KB Output is correct
43 Correct 22 ms 28280 KB Output is correct
44 Correct 10 ms 10744 KB Output is correct
45 Correct 23 ms 29432 KB Output is correct
46 Correct 15 ms 20984 KB Output is correct
47 Correct 22 ms 29944 KB Output is correct
48 Correct 17 ms 23416 KB Output is correct
49 Correct 21 ms 28152 KB Output is correct
50 Correct 12 ms 14840 KB Output is correct
51 Correct 20 ms 28152 KB Output is correct
52 Correct 9 ms 9976 KB Output is correct
53 Correct 19 ms 27384 KB Output is correct
54 Correct 11 ms 13048 KB Output is correct
55 Correct 20 ms 29176 KB Output is correct
56 Correct 13 ms 16120 KB Output is correct
57 Correct 21 ms 30456 KB Output is correct
58 Correct 15 ms 17912 KB Output is correct
59 Correct 92 ms 127992 KB Output is correct
60 Correct 52 ms 86008 KB Output is correct
61 Correct 93 ms 127992 KB Output is correct
62 Correct 50 ms 84984 KB Output is correct
63 Correct 93 ms 127992 KB Output is correct
64 Correct 54 ms 86008 KB Output is correct
65 Correct 79 ms 115576 KB Output is correct
66 Correct 73 ms 106104 KB Output is correct
67 Correct 66 ms 101496 KB Output is correct
68 Correct 62 ms 93688 KB Output is correct
69 Correct 77 ms 114296 KB Output is correct
70 Correct 84 ms 109816 KB Output is correct
71 Correct 71 ms 110584 KB Output is correct
72 Correct 95 ms 112120 KB Output is correct
73 Correct 62 ms 103800 KB Output is correct
74 Correct 76 ms 97144 KB Output is correct
75 Correct 74 ms 107128 KB Output is correct
76 Correct 90 ms 122944 KB Output is correct
77 Correct 80 ms 122876 KB Output is correct
78 Correct 71 ms 94796 KB Output is correct
79 Correct 70 ms 98168 KB Output is correct
80 Correct 90 ms 120440 KB Output is correct
81 Correct 64 ms 99192 KB Output is correct
82 Correct 66 ms 104824 KB Output is correct
83 Correct 89 ms 127864 KB Output is correct
84 Correct 73 ms 109432 KB Output is correct
85 Correct 74 ms 119288 KB Output is correct
86 Correct 80 ms 116652 KB Output is correct
87 Correct 76 ms 107272 KB Output is correct
88 Correct 100 ms 128764 KB Output is correct
89 Correct 101 ms 128796 KB Output is correct
90 Correct 66 ms 108152 KB Output is correct
91 Correct 98 ms 128760 KB Output is correct
92 Correct 94 ms 128760 KB Output is correct
93 Correct 77 ms 126432 KB Output is correct