Submission #245054

# Submission time Handle Problem Language Result Execution time Memory
245054 2020-07-05T11:29:06 Z vioalbert Collecting Stamps 3 (JOI20_ho_t3) C++14
25 / 100
2000 ms 114948 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

void read() {
	cin >> n >> l;
	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 dist[n+2][n+2][n+2][2];
	for(int i = 1; i <= n+1; i++) {
		for(int j = i-1; j <= n; j++) {
			for(int k = 0; k <= n; k++)
				dist[i][j][k][0] = dist[i][j][k][1] = -1;
		}
	}
	ll cost, total;
	int ans = 0;
	pq.emplace(0, state(1, n, 0, 0));
	dist[1][n][0][0] = 0;
	while(!pq.empty()) {
		ll d = pq.top().first; state u = pq.top().second; pq.pop();
		if(dist[u.l][u.r][u.cnt][u.dir] == d) {
			if(u.l > u.r) {
				ans = max(ans, u.cnt);
				continue;
			}

			if(u.dir == 0) {
				cost = ((u.l==1)?0:-cl[u.l-1]) + cl[u.l];
				total = d + cost;
				ll& nxt1 = dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0];
				if(nxt1 == -1 || nxt1 > total) {
					nxt1 = total;
					pq.emplace(nxt1, state(u.l+1, u.r, u.cnt + (total <= t[u.l]), 0));
				}

				cost = ((u.l==1)?0:cl[u.l-1]) + ccl[u.r];
				total = d + cost;
				ll& nxt2 = dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1];
				if(nxt2 == -1 || nxt2 > total) {
					nxt2 = total;
					pq.emplace(nxt2, state(u.l, u.r-1, u.cnt + (total <= t[u.r]), 1));
				}
			} else {
				cost = ((u.r==n)?0:-ccl[u.r+1]) + ccl[u.r];
				total = d + cost;
				ll& nxt1 = dist[u.l][u.r-1][u.cnt + (total <= t[u.r])][1];
				if(nxt1 == -1 || nxt1 > total) {
					nxt1 = total;
					pq.emplace(nxt1, state(u.l, u.r-1, u.cnt + (total <= t[u.r]), 1));
				}

				cost = ((u.r==n)?0:ccl[u.r+1]) + cl[u.l];
				total = d + cost;
				ll& nxt2 = dist[u.l+1][u.r][u.cnt + (total <= t[u.l])][0];
				if(nxt2 == -1 || nxt2 > total) {
					nxt2 = total;
					pq.emplace(nxt2, state(u.l+1, u.r, u.cnt + (total <= t[u.l]), 0));
				}
			}
		}
	}
	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 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 1222 ms 59716 KB Output is correct
19 Correct 501 ms 29024 KB Output is correct
20 Correct 129 ms 12524 KB Output is correct
21 Correct 442 ms 27360 KB Output is correct
22 Correct 702 ms 42968 KB Output is correct
23 Correct 137 ms 10604 KB Output is correct
24 Correct 40 ms 6904 KB Output is correct
25 Correct 116 ms 10348 KB Output is correct
26 Correct 19 ms 2624 KB Output is correct
27 Correct 152 ms 10600 KB Output is correct
28 Correct 34 ms 6520 KB Output is correct
29 Correct 109 ms 10984 KB Output is correct
30 Correct 42 ms 7288 KB Output is correct
31 Correct 107 ms 10348 KB Output is correct
32 Correct 35 ms 3964 KB Output is correct
33 Correct 97 ms 8816 KB Output is correct
34 Correct 17 ms 2812 KB Output is correct
35 Correct 32 ms 7488 KB Output is correct
36 Correct 21 ms 3580 KB Output is correct
37 Correct 37 ms 8700 KB Output is correct
38 Correct 34 ms 4348 KB Output is correct
39 Correct 37 ms 8948 KB Output is correct
40 Correct 25 ms 4860 KB Output is correct
41 Correct 1878 ms 89416 KB Output is correct
42 Correct 34 ms 36684 KB Output is correct
43 Correct 1888 ms 89288 KB Output is correct
44 Correct 36 ms 35776 KB Output is correct
45 Correct 1888 ms 89292 KB Output is correct
46 Correct 32 ms 36544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 1222 ms 59716 KB Output is correct
37 Correct 501 ms 29024 KB Output is correct
38 Correct 129 ms 12524 KB Output is correct
39 Correct 442 ms 27360 KB Output is correct
40 Correct 702 ms 42968 KB Output is correct
41 Correct 137 ms 10604 KB Output is correct
42 Correct 40 ms 6904 KB Output is correct
43 Correct 116 ms 10348 KB Output is correct
44 Correct 19 ms 2624 KB Output is correct
45 Correct 152 ms 10600 KB Output is correct
46 Correct 34 ms 6520 KB Output is correct
47 Correct 109 ms 10984 KB Output is correct
48 Correct 42 ms 7288 KB Output is correct
49 Correct 107 ms 10348 KB Output is correct
50 Correct 35 ms 3964 KB Output is correct
51 Correct 97 ms 8816 KB Output is correct
52 Correct 17 ms 2812 KB Output is correct
53 Correct 32 ms 7488 KB Output is correct
54 Correct 21 ms 3580 KB Output is correct
55 Correct 37 ms 8700 KB Output is correct
56 Correct 34 ms 4348 KB Output is correct
57 Correct 37 ms 8948 KB Output is correct
58 Correct 25 ms 4860 KB Output is correct
59 Correct 1878 ms 89416 KB Output is correct
60 Correct 34 ms 36684 KB Output is correct
61 Correct 1888 ms 89288 KB Output is correct
62 Correct 36 ms 35776 KB Output is correct
63 Correct 1888 ms 89292 KB Output is correct
64 Correct 32 ms 36544 KB Output is correct
65 Correct 1464 ms 80328 KB Output is correct
66 Correct 1352 ms 73672 KB Output is correct
67 Correct 1198 ms 58336 KB Output is correct
68 Correct 943 ms 53208 KB Output is correct
69 Correct 1687 ms 79304 KB Output is correct
70 Correct 1455 ms 76188 KB Output is correct
71 Correct 1166 ms 76872 KB Output is correct
72 Correct 1670 ms 77832 KB Output is correct
73 Correct 570 ms 59732 KB Output is correct
74 Correct 1107 ms 55296 KB Output is correct
75 Correct 1080 ms 74568 KB Output is correct
76 Correct 1461 ms 85712 KB Output is correct
77 Correct 1489 ms 85576 KB Output is correct
78 Correct 937 ms 53876 KB Output is correct
79 Correct 1249 ms 68568 KB Output is correct
80 Correct 1427 ms 83924 KB Output is correct
81 Correct 1049 ms 69064 KB Output is correct
82 Correct 525 ms 60504 KB Output is correct
83 Correct 1626 ms 89288 KB Output is correct
84 Correct 621 ms 63876 KB Output is correct
85 Correct 859 ms 82888 KB Output is correct
86 Correct 730 ms 68952 KB Output is correct
87 Correct 1449 ms 74440 KB Output is correct
88 Execution timed out 2091 ms 114948 KB Time limit exceeded
89 Halted 0 ms 0 KB -