Submission #206703

# Submission time Handle Problem Language Result Execution time Memory
206703 2020-03-04T16:09:22 Z Saboon Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
77 ms 72952 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 200 + 10;
const int inf= 1e9 + 1;

int L;
int dp[maxn][maxn][maxn], pd[maxn][maxn][maxn];
int x[maxn], t[maxn];

int dis(int x, int y){
	if (x > y)
		swap(x, y);
	return min(y - x, L - y + x);
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n >> L;
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	for (int i = 1; i <= n; i++)
		cin >> t[i];
	int answer = 0;
	x[0] = 0, x[n + 1] = 0;
	memset(dp, 63, sizeof dp);
	memset(pd, 63, sizeof pd);
	dp[0][0][0] = pd[0][0][0] = 0;
	for (int i = 0; i <= n; i++){
		for (int j = 0; i + j <= n; j++){
			if (i + j == 0)
				continue;
			int iidx = i, jidx = n-j+1;
			for (int k = 0; k <= i + j; k++){
				if (j > 0){
					dp[i][j][k] = min(dp[i][j-1][k] + dis(x[jidx], x[jidx+1]), pd[i][j-1][k] + dis(x[jidx], x[iidx]));
					if (k > 0){
						if (dp[i][j-1][k-1] + dis(x[jidx], x[jidx+1]) <= t[jidx])
							dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][k-1] + dis(x[jidx], x[jidx+1]));
						if (pd[i][j-1][k-1] + dis(x[jidx], x[iidx]) <= t[jidx])
							dp[i][j][k] = min(dp[i][j][k], pd[i][j-1][k-1] + dis(x[jidx], x[iidx]));
					}
				}
				if (i > 0){
					pd[i][j][k] = min(pd[i-1][j][k] + dis(x[iidx], x[iidx-1]), dp[i-1][j][k] + dis(x[iidx], x[jidx]));
					if (k > 0){
						if (pd[i-1][j][k-1] + dis(x[iidx], x[iidx-1]) <= t[iidx])
							pd[i][j][k] = min(pd[i][j][k], pd[i-1][j][k-1] + dis(x[iidx], x[iidx-1]));
						if (dp[i-1][j][k-1] + dis(x[iidx], x[jidx]) <= t[iidx])
							pd[i][j][k] = min(pd[i][j][k], dp[i-1][j][k-1] + dis(x[iidx], x[jidx]));
					}
				}
				if (dp[i][j][k] < inf or pd[i][j][k] < inf)
					answer = max(answer, k);
			}
		}
	}
	cout << answer << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 72824 KB Output is correct
2 Correct 45 ms 72824 KB Output is correct
3 Correct 44 ms 72824 KB Output is correct
4 Correct 45 ms 72952 KB Output is correct
5 Correct 44 ms 72824 KB Output is correct
6 Correct 43 ms 72824 KB Output is correct
7 Correct 44 ms 72828 KB Output is correct
8 Correct 44 ms 72824 KB Output is correct
9 Correct 45 ms 72824 KB Output is correct
10 Correct 45 ms 72760 KB Output is correct
11 Correct 43 ms 72824 KB Output is correct
12 Correct 44 ms 72824 KB Output is correct
13 Correct 46 ms 72824 KB Output is correct
14 Correct 44 ms 72824 KB Output is correct
15 Correct 44 ms 72824 KB Output is correct
16 Correct 45 ms 72824 KB Output is correct
17 Correct 44 ms 72824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 72824 KB Output is correct
2 Correct 45 ms 72824 KB Output is correct
3 Correct 44 ms 72824 KB Output is correct
4 Correct 45 ms 72952 KB Output is correct
5 Correct 44 ms 72824 KB Output is correct
6 Correct 43 ms 72824 KB Output is correct
7 Correct 44 ms 72828 KB Output is correct
8 Correct 44 ms 72824 KB Output is correct
9 Correct 45 ms 72824 KB Output is correct
10 Correct 45 ms 72760 KB Output is correct
11 Correct 43 ms 72824 KB Output is correct
12 Correct 44 ms 72824 KB Output is correct
13 Correct 46 ms 72824 KB Output is correct
14 Correct 44 ms 72824 KB Output is correct
15 Correct 44 ms 72824 KB Output is correct
16 Correct 45 ms 72824 KB Output is correct
17 Correct 44 ms 72824 KB Output is correct
18 Correct 44 ms 72824 KB Output is correct
19 Correct 44 ms 72828 KB Output is correct
20 Correct 43 ms 72824 KB Output is correct
21 Correct 43 ms 72824 KB Output is correct
22 Correct 46 ms 72816 KB Output is correct
23 Correct 43 ms 72832 KB Output is correct
24 Correct 43 ms 72824 KB Output is correct
25 Correct 45 ms 72824 KB Output is correct
26 Correct 45 ms 72824 KB Output is correct
27 Correct 43 ms 72824 KB Output is correct
28 Correct 44 ms 72824 KB Output is correct
29 Correct 45 ms 72952 KB Output is correct
30 Correct 43 ms 72824 KB Output is correct
31 Correct 45 ms 72824 KB Output is correct
32 Correct 44 ms 72824 KB Output is correct
33 Correct 43 ms 72824 KB Output is correct
34 Correct 45 ms 72824 KB Output is correct
35 Correct 43 ms 72824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 72824 KB Output is correct
2 Correct 45 ms 72824 KB Output is correct
3 Correct 44 ms 72824 KB Output is correct
4 Correct 45 ms 72952 KB Output is correct
5 Correct 44 ms 72824 KB Output is correct
6 Correct 43 ms 72824 KB Output is correct
7 Correct 44 ms 72828 KB Output is correct
8 Correct 44 ms 72824 KB Output is correct
9 Correct 45 ms 72824 KB Output is correct
10 Correct 45 ms 72760 KB Output is correct
11 Correct 43 ms 72824 KB Output is correct
12 Correct 44 ms 72824 KB Output is correct
13 Correct 46 ms 72824 KB Output is correct
14 Correct 44 ms 72824 KB Output is correct
15 Correct 44 ms 72824 KB Output is correct
16 Correct 45 ms 72824 KB Output is correct
17 Correct 44 ms 72824 KB Output is correct
18 Correct 64 ms 72824 KB Output is correct
19 Correct 71 ms 72824 KB Output is correct
20 Correct 48 ms 72824 KB Output is correct
21 Correct 56 ms 72824 KB Output is correct
22 Correct 61 ms 72824 KB Output is correct
23 Correct 49 ms 72824 KB Output is correct
24 Correct 47 ms 72824 KB Output is correct
25 Correct 47 ms 72824 KB Output is correct
26 Correct 45 ms 72824 KB Output is correct
27 Correct 48 ms 72824 KB Output is correct
28 Correct 45 ms 72824 KB Output is correct
29 Correct 47 ms 72824 KB Output is correct
30 Correct 48 ms 72952 KB Output is correct
31 Correct 48 ms 72824 KB Output is correct
32 Correct 46 ms 72824 KB Output is correct
33 Correct 47 ms 72824 KB Output is correct
34 Correct 45 ms 72824 KB Output is correct
35 Correct 46 ms 72824 KB Output is correct
36 Correct 44 ms 72824 KB Output is correct
37 Correct 48 ms 72824 KB Output is correct
38 Correct 46 ms 72824 KB Output is correct
39 Correct 47 ms 72952 KB Output is correct
40 Correct 46 ms 72824 KB Output is correct
41 Correct 71 ms 72824 KB Output is correct
42 Correct 60 ms 72824 KB Output is correct
43 Correct 71 ms 72824 KB Output is correct
44 Correct 60 ms 72824 KB Output is correct
45 Correct 72 ms 72824 KB Output is correct
46 Correct 59 ms 72824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 72824 KB Output is correct
2 Correct 45 ms 72824 KB Output is correct
3 Correct 44 ms 72824 KB Output is correct
4 Correct 45 ms 72952 KB Output is correct
5 Correct 44 ms 72824 KB Output is correct
6 Correct 43 ms 72824 KB Output is correct
7 Correct 44 ms 72828 KB Output is correct
8 Correct 44 ms 72824 KB Output is correct
9 Correct 45 ms 72824 KB Output is correct
10 Correct 45 ms 72760 KB Output is correct
11 Correct 43 ms 72824 KB Output is correct
12 Correct 44 ms 72824 KB Output is correct
13 Correct 46 ms 72824 KB Output is correct
14 Correct 44 ms 72824 KB Output is correct
15 Correct 44 ms 72824 KB Output is correct
16 Correct 45 ms 72824 KB Output is correct
17 Correct 44 ms 72824 KB Output is correct
18 Correct 44 ms 72824 KB Output is correct
19 Correct 44 ms 72828 KB Output is correct
20 Correct 43 ms 72824 KB Output is correct
21 Correct 43 ms 72824 KB Output is correct
22 Correct 46 ms 72816 KB Output is correct
23 Correct 43 ms 72832 KB Output is correct
24 Correct 43 ms 72824 KB Output is correct
25 Correct 45 ms 72824 KB Output is correct
26 Correct 45 ms 72824 KB Output is correct
27 Correct 43 ms 72824 KB Output is correct
28 Correct 44 ms 72824 KB Output is correct
29 Correct 45 ms 72952 KB Output is correct
30 Correct 43 ms 72824 KB Output is correct
31 Correct 45 ms 72824 KB Output is correct
32 Correct 44 ms 72824 KB Output is correct
33 Correct 43 ms 72824 KB Output is correct
34 Correct 45 ms 72824 KB Output is correct
35 Correct 43 ms 72824 KB Output is correct
36 Correct 64 ms 72824 KB Output is correct
37 Correct 71 ms 72824 KB Output is correct
38 Correct 48 ms 72824 KB Output is correct
39 Correct 56 ms 72824 KB Output is correct
40 Correct 61 ms 72824 KB Output is correct
41 Correct 49 ms 72824 KB Output is correct
42 Correct 47 ms 72824 KB Output is correct
43 Correct 47 ms 72824 KB Output is correct
44 Correct 45 ms 72824 KB Output is correct
45 Correct 48 ms 72824 KB Output is correct
46 Correct 45 ms 72824 KB Output is correct
47 Correct 47 ms 72824 KB Output is correct
48 Correct 48 ms 72952 KB Output is correct
49 Correct 48 ms 72824 KB Output is correct
50 Correct 46 ms 72824 KB Output is correct
51 Correct 47 ms 72824 KB Output is correct
52 Correct 45 ms 72824 KB Output is correct
53 Correct 46 ms 72824 KB Output is correct
54 Correct 44 ms 72824 KB Output is correct
55 Correct 48 ms 72824 KB Output is correct
56 Correct 46 ms 72824 KB Output is correct
57 Correct 47 ms 72952 KB Output is correct
58 Correct 46 ms 72824 KB Output is correct
59 Correct 71 ms 72824 KB Output is correct
60 Correct 60 ms 72824 KB Output is correct
61 Correct 71 ms 72824 KB Output is correct
62 Correct 60 ms 72824 KB Output is correct
63 Correct 72 ms 72824 KB Output is correct
64 Correct 59 ms 72824 KB Output is correct
65 Correct 68 ms 72824 KB Output is correct
66 Correct 64 ms 72880 KB Output is correct
67 Correct 63 ms 72828 KB Output is correct
68 Correct 62 ms 72952 KB Output is correct
69 Correct 66 ms 72824 KB Output is correct
70 Correct 71 ms 72824 KB Output is correct
71 Correct 65 ms 72824 KB Output is correct
72 Correct 77 ms 72824 KB Output is correct
73 Correct 63 ms 72824 KB Output is correct
74 Correct 65 ms 72824 KB Output is correct
75 Correct 64 ms 72824 KB Output is correct
76 Correct 73 ms 72824 KB Output is correct
77 Correct 69 ms 72824 KB Output is correct
78 Correct 64 ms 72824 KB Output is correct
79 Correct 62 ms 72952 KB Output is correct
80 Correct 72 ms 72824 KB Output is correct
81 Correct 67 ms 72824 KB Output is correct
82 Correct 64 ms 72824 KB Output is correct
83 Correct 71 ms 72824 KB Output is correct
84 Correct 65 ms 72824 KB Output is correct
85 Correct 68 ms 72824 KB Output is correct
86 Correct 68 ms 72824 KB Output is correct
87 Correct 65 ms 72824 KB Output is correct
88 Correct 75 ms 72824 KB Output is correct
89 Correct 70 ms 72824 KB Output is correct
90 Correct 65 ms 72952 KB Output is correct
91 Correct 72 ms 72824 KB Output is correct
92 Correct 72 ms 72952 KB Output is correct
93 Correct 70 ms 72824 KB Output is correct