Submission #256354

# Submission time Handle Problem Language Result Execution time Memory
256354 2020-08-02T15:10:04 Z vioalbert Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
132 ms 129404 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll N = 205, INF = 1e18;
ll n, l;
ll cl[N], ccl[N], t[N];

void read() {
	cin >> n >> l;
	cl[0] = 0, cl[n+1] = l;
	ccl[0] = l, cl[n+1] = 0;
	for(int i = 1; i <= n; i++) {
		cin >> cl[i];
		ccl[i] = l - cl[i];
	}
	for(int i = 1; i <= n; i++)
		cin >> t[i];
}

struct state {
	int l, r, cnt, dir;
	state(int _l, int _r, int _cnt, int _dir) : l(_l), r(_r), cnt(_cnt), dir(_dir) {}
	bool operator<(const state& ot) const {
		return cnt < ot.cnt;
	}
};

void solve() {
	priority_queue<pair<ll, state>, vector<pair<ll, state>>, greater<pair<ll, state>>> pq;
	ll dp[n+2][n+2][n+2][2];
	for(int l = 0; l <= n+1; l++) {
		for(int r = 0; r <= n+1; r++) {
			for(int cnt = 0; cnt <= n; cnt++)
				dp[l][r][cnt][0] = dp[l][r][cnt][1] = INF;
		}
	}
	dp[0][n+1][0][0] = 0;

	for(int l = 0; l <= n+1; l++) {
		for(int r = n+1; r > l; r--) {
			for(int cnt = 0; cnt <= n; cnt++) {
				// cerr << l << ' ' << r << ' ' << cnt << '\n';
				ll dur;
				if(dp[l][r][cnt][0] < INF) {
					dur = dp[l][r][cnt][0] + cl[l + 1] - cl[l];
					dp[l + 1][r][cnt + (dur <= t[l + 1])][0] = min(dp[l + 1][r][cnt + (dur <= t[l + 1])][0], dur);
					dur = dp[l][r][cnt][0] + cl[l] + ccl[r - 1];
					dp[l][r - 1][cnt + (dur <= t[r - 1])][1] = min(dp[l][r - 1][cnt + (dur <= t[r - 1])][1], dur);
				}
				if(dp[l][r][cnt][1] < INF) {
					dur = dp[l][r][cnt][1] + ccl[r - 1] - ccl[r];
					dp[l][r - 1][cnt + (dur <= t[r - 1])][1] = min(dp[l][r - 1][cnt + (dur <= t[r - 1])][1], dur);
					dur = dp[l][r][cnt][1] + ccl[r] + cl[l + 1];
					dp[l + 1][r][cnt + (dur <= t[l + 1])][0] = min(dp[l + 1][r][cnt + (dur <= t[l + 1])][0], dur);
				}
			}
		}
	}

	ll ans = 0;
	for(int l = 0; l <= n; l++) {
		for(int r = l+1; r <= n+1; r++) {
			for(int cnt = 0; cnt <= n; cnt++) {
				if(min(dp[l][r][cnt][0], dp[l][r][cnt][1]) < INF)
					ans = max(ans, (ll)cnt);
			}
		}
	}

	cout << ans << '\n';
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	read();
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 81 ms 93296 KB Output is correct
19 Correct 40 ms 44160 KB Output is correct
20 Correct 15 ms 17408 KB Output is correct
21 Correct 36 ms 40576 KB Output is correct
22 Correct 54 ms 59816 KB Output is correct
23 Correct 16 ms 13696 KB Output is correct
24 Correct 11 ms 9600 KB Output is correct
25 Correct 14 ms 13312 KB Output is correct
26 Correct 3 ms 3328 KB Output is correct
27 Correct 13 ms 14208 KB Output is correct
28 Correct 8 ms 8704 KB Output is correct
29 Correct 13 ms 14592 KB Output is correct
30 Correct 9 ms 10240 KB Output is correct
31 Correct 12 ms 13312 KB Output is correct
32 Correct 5 ms 5248 KB Output is correct
33 Correct 14 ms 13312 KB Output is correct
34 Correct 4 ms 3072 KB Output is correct
35 Correct 12 ms 12928 KB Output is correct
36 Correct 4 ms 4480 KB Output is correct
37 Correct 10 ms 14208 KB Output is correct
38 Correct 6 ms 5888 KB Output is correct
39 Correct 11 ms 15104 KB Output is correct
40 Correct 7 ms 6912 KB Output is correct
41 Correct 116 ms 127516 KB Output is correct
42 Correct 47 ms 70648 KB Output is correct
43 Correct 128 ms 127512 KB Output is correct
44 Correct 50 ms 69372 KB Output is correct
45 Correct 127 ms 127512 KB Output is correct
46 Correct 52 ms 70648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 81 ms 93296 KB Output is correct
37 Correct 40 ms 44160 KB Output is correct
38 Correct 15 ms 17408 KB Output is correct
39 Correct 36 ms 40576 KB Output is correct
40 Correct 54 ms 59816 KB Output is correct
41 Correct 16 ms 13696 KB Output is correct
42 Correct 11 ms 9600 KB Output is correct
43 Correct 14 ms 13312 KB Output is correct
44 Correct 3 ms 3328 KB Output is correct
45 Correct 13 ms 14208 KB Output is correct
46 Correct 8 ms 8704 KB Output is correct
47 Correct 13 ms 14592 KB Output is correct
48 Correct 9 ms 10240 KB Output is correct
49 Correct 12 ms 13312 KB Output is correct
50 Correct 5 ms 5248 KB Output is correct
51 Correct 14 ms 13312 KB Output is correct
52 Correct 4 ms 3072 KB Output is correct
53 Correct 12 ms 12928 KB Output is correct
54 Correct 4 ms 4480 KB Output is correct
55 Correct 10 ms 14208 KB Output is correct
56 Correct 6 ms 5888 KB Output is correct
57 Correct 11 ms 15104 KB Output is correct
58 Correct 7 ms 6912 KB Output is correct
59 Correct 116 ms 127516 KB Output is correct
60 Correct 47 ms 70648 KB Output is correct
61 Correct 128 ms 127512 KB Output is correct
62 Correct 50 ms 69372 KB Output is correct
63 Correct 127 ms 127512 KB Output is correct
64 Correct 52 ms 70648 KB Output is correct
65 Correct 105 ms 109432 KB Output is correct
66 Correct 88 ms 96248 KB Output is correct
67 Correct 82 ms 90104 KB Output is correct
68 Correct 71 ms 79992 KB Output is correct
69 Correct 98 ms 107768 KB Output is correct
70 Correct 102 ms 101112 KB Output is correct
71 Correct 102 ms 102648 KB Output is correct
72 Correct 93 ms 104440 KB Output is correct
73 Correct 71 ms 93180 KB Output is correct
74 Correct 83 ms 84216 KB Output is correct
75 Correct 83 ms 97912 KB Output is correct
76 Correct 113 ms 120192 KB Output is correct
77 Correct 103 ms 120056 KB Output is correct
78 Correct 76 ms 81400 KB Output is correct
79 Correct 82 ms 85624 KB Output is correct
80 Correct 107 ms 116472 KB Output is correct
81 Correct 75 ms 87424 KB Output is correct
82 Correct 74 ms 94712 KB Output is correct
83 Correct 111 ms 127480 KB Output is correct
84 Correct 87 ms 101248 KB Output is correct
85 Correct 90 ms 114680 KB Output is correct
86 Correct 98 ms 111224 KB Output is correct
87 Correct 88 ms 97912 KB Output is correct
88 Correct 132 ms 129400 KB Output is correct
89 Correct 119 ms 129404 KB Output is correct
90 Correct 63 ms 99448 KB Output is correct
91 Correct 129 ms 129400 KB Output is correct
92 Correct 115 ms 129400 KB Output is correct
93 Correct 80 ms 125560 KB Output is correct