답안 #1045005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045005 2024-08-05T15:35:11 Z TAhmed33 Collecting Stamps 3 (JOI20_ho_t3) C++
15 / 100
161 ms 66136 KB
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int dp[203][203][203][2];
int n, l, a[203], t[203];
int ans (int x, int y, int z, int c) { //left, right, count, is it at right?
	if (x == n + 1 && y == 0) {
		if (z == 0) return 0;
		return inf;
	}
	if (z < 0) return inf;
	int &ret = dp[x][y][z][c];
	if (ret != -1) return ret;
	ret = inf;
	if (c == 0) {
		if (x != n + 1) {
			if (y != 0) {
				int cost = l - a[x] + a[y];
				ret = min(ret, ans(x + 1, y, z, 1) + cost);
				if (ans(x + 1, y, z - 1, 1) + cost <= t[x]) {
					ret = min(ret, ans(x + 1, y, z - 1, 1) + cost);
				}
			}
			if (x != n + 1) {
				int cost = a[x + 1] - a[x];
				ret = min(ret, ans(x + 1, y, z, 0) + cost);
				if (ans(x + 1, y, z - 1, 0) + cost <= t[x]) {
					ret = min(ret, ans(x + 1, y, z - 1, 0) + cost);
				}
			}
		}
	} else {
		if (y != 0) {
			if (x != n + 1) {
				int cost = l - a[x] + a[y];
				ret = min(ret, ans(x, y - 1, z, 0) + cost);
				if (ans(x, y - 1, z - 1, 0) + cost <= t[y]) {
					ret = min(ret, ans(x, y - 1, z - 1, 0) + cost);
				}
			}
			if (y != 0) {
				int cost = a[y] - a[y - 1];
				ret = min(ret, ans(x, y - 1, z, 1) + cost);
				if (ans(x, y - 1, z - 1, 1) + cost <= t[y]) {
					ret = min(ret, ans(x, y - 1, z - 1, 1) + cost);
				}
			}
		}
	}
	return ret;
}
void solve () {
	cin >> n >> l;
	a[0] = 0; a[n + 1] = l;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	memset(dp, -1, sizeof(dp));
	int ret = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= n + 1; j++) {
			for (int k = j + 1; k <= n + 1; k++) {
				if (ans(k, j, i, 0) != inf || ans(k, j, i, 1) != inf) {
					ret = i;
				}
			}
		}
	}
	cout << ret << '\n';
}		
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	int tc = 1; //cin >> tc;
	while (tc--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 65884 KB Output is correct
2 Correct 9 ms 65740 KB Output is correct
3 Correct 8 ms 65884 KB Output is correct
4 Correct 8 ms 65700 KB Output is correct
5 Correct 9 ms 65884 KB Output is correct
6 Correct 8 ms 65708 KB Output is correct
7 Correct 8 ms 65884 KB Output is correct
8 Correct 7 ms 65764 KB Output is correct
9 Correct 9 ms 65884 KB Output is correct
10 Correct 8 ms 65884 KB Output is correct
11 Correct 8 ms 65884 KB Output is correct
12 Correct 9 ms 65884 KB Output is correct
13 Correct 8 ms 65776 KB Output is correct
14 Correct 9 ms 65896 KB Output is correct
15 Correct 8 ms 65884 KB Output is correct
16 Correct 8 ms 65708 KB Output is correct
17 Correct 8 ms 65884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 65884 KB Output is correct
2 Correct 9 ms 65740 KB Output is correct
3 Correct 8 ms 65884 KB Output is correct
4 Correct 8 ms 65700 KB Output is correct
5 Correct 9 ms 65884 KB Output is correct
6 Correct 8 ms 65708 KB Output is correct
7 Correct 8 ms 65884 KB Output is correct
8 Correct 7 ms 65764 KB Output is correct
9 Correct 9 ms 65884 KB Output is correct
10 Correct 8 ms 65884 KB Output is correct
11 Correct 8 ms 65884 KB Output is correct
12 Correct 9 ms 65884 KB Output is correct
13 Correct 8 ms 65776 KB Output is correct
14 Correct 9 ms 65896 KB Output is correct
15 Correct 8 ms 65884 KB Output is correct
16 Correct 8 ms 65708 KB Output is correct
17 Correct 8 ms 65884 KB Output is correct
18 Incorrect 8 ms 65884 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 65884 KB Output is correct
2 Correct 9 ms 65740 KB Output is correct
3 Correct 8 ms 65884 KB Output is correct
4 Correct 8 ms 65700 KB Output is correct
5 Correct 9 ms 65884 KB Output is correct
6 Correct 8 ms 65708 KB Output is correct
7 Correct 8 ms 65884 KB Output is correct
8 Correct 7 ms 65764 KB Output is correct
9 Correct 9 ms 65884 KB Output is correct
10 Correct 8 ms 65884 KB Output is correct
11 Correct 8 ms 65884 KB Output is correct
12 Correct 9 ms 65884 KB Output is correct
13 Correct 8 ms 65776 KB Output is correct
14 Correct 9 ms 65896 KB Output is correct
15 Correct 8 ms 65884 KB Output is correct
16 Correct 8 ms 65708 KB Output is correct
17 Correct 8 ms 65884 KB Output is correct
18 Correct 119 ms 65884 KB Output is correct
19 Correct 61 ms 65884 KB Output is correct
20 Correct 28 ms 65884 KB Output is correct
21 Correct 54 ms 65884 KB Output is correct
22 Correct 81 ms 65884 KB Output is correct
23 Correct 24 ms 65948 KB Output is correct
24 Correct 19 ms 65724 KB Output is correct
25 Correct 23 ms 65884 KB Output is correct
26 Correct 12 ms 65884 KB Output is correct
27 Correct 28 ms 65948 KB Output is correct
28 Correct 19 ms 65884 KB Output is correct
29 Correct 32 ms 65884 KB Output is correct
30 Correct 20 ms 65884 KB Output is correct
31 Correct 23 ms 66136 KB Output is correct
32 Correct 15 ms 65884 KB Output is correct
33 Correct 24 ms 65944 KB Output is correct
34 Correct 12 ms 65884 KB Output is correct
35 Correct 24 ms 65936 KB Output is correct
36 Correct 14 ms 65884 KB Output is correct
37 Correct 25 ms 65736 KB Output is correct
38 Correct 15 ms 65952 KB Output is correct
39 Correct 28 ms 65732 KB Output is correct
40 Correct 14 ms 65880 KB Output is correct
41 Correct 161 ms 65884 KB Output is correct
42 Correct 99 ms 65884 KB Output is correct
43 Correct 160 ms 65936 KB Output is correct
44 Correct 92 ms 65884 KB Output is correct
45 Correct 158 ms 65884 KB Output is correct
46 Correct 98 ms 66132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 65884 KB Output is correct
2 Correct 9 ms 65740 KB Output is correct
3 Correct 8 ms 65884 KB Output is correct
4 Correct 8 ms 65700 KB Output is correct
5 Correct 9 ms 65884 KB Output is correct
6 Correct 8 ms 65708 KB Output is correct
7 Correct 8 ms 65884 KB Output is correct
8 Correct 7 ms 65764 KB Output is correct
9 Correct 9 ms 65884 KB Output is correct
10 Correct 8 ms 65884 KB Output is correct
11 Correct 8 ms 65884 KB Output is correct
12 Correct 9 ms 65884 KB Output is correct
13 Correct 8 ms 65776 KB Output is correct
14 Correct 9 ms 65896 KB Output is correct
15 Correct 8 ms 65884 KB Output is correct
16 Correct 8 ms 65708 KB Output is correct
17 Correct 8 ms 65884 KB Output is correct
18 Incorrect 8 ms 65884 KB Output isn't correct
19 Halted 0 ms 0 KB -