Submission #388002

# Submission time Handle Problem Language Result Execution time Memory
388002 2021-04-09T17:16:55 Z nikatamliani Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
313 ms 8396 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 505, oo = 1e18+10;
ll dp[N][N][2], save_dp[N][N][2], x[N], t[N];
ll n, s;
ll dist(ll i, ll j) {
	if(x[i] > x[j]) {
		swap(i, j);
	}
	return min(x[j] - x[i], x[i] + s - x[j]);
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> s;
	for(int i = 1; i <= n; ++i) {
		cin >> x[i];
	}
	for(int i = 1; i <= n; ++i) {
		cin >> t[i];
	}
	x[n+1] = 0;
	for(int i = n+2; i <= 2*n+1; ++i) {
		x[i] = x[i - n - 1];
		t[i] = t[i - n - 1];
	}
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			save_dp[i][j][0] = save_dp[i][j][1] = oo;
			dp[i][j][0] = dp[i][j][1] = oo;
		}
	}
	for(int R = n+1; R <= 2*n+1; ++R) {
		for(int L = n+1; L >= R-n; --L) {
			save_dp[L][R][0] = dist(n+1, R) + dist(L, R);
			save_dp[L][R][1] = dist(n+1, L) + dist(L, R);
		}
	}
	ll ans = 0;
	auto mini = [](ll &x, ll y) {
		x = min(x, y);
	};
	for(int X = 1; X <= n; ++X) {
		for(int R = n+1; R <= 2*n+1; ++R) {
			for(int L = n+1; L >= R-n; --L) {
				ll &bestL = dp[L][R][0];
				ll &bestR = dp[L][R][1];
				if(L < n + 1) {
					ll opt0 = min(save_dp[L+1][R][0] + dist(L, L+1), save_dp[L+1][R][1] + dist(L, R));
					if(opt0 <= t[L]) mini(bestL, opt0);
					mini(bestL, dp[L+1][R][0] + dist(L, L+1));
					mini(bestL, dp[L+1][R][1] + dist(L, R));
				}
				if(R > n + 1) {
					ll opt0 = min(save_dp[L][R-1][1] + dist(R-1, R), save_dp[L][R-1][0] + dist(L, R));
					if(opt0 <= t[R]) mini(bestR, opt0);
					mini(bestR, dp[L][R-1][1] + dist(R-1, R));
					mini(bestR, dp[L][R-1][0] + dist(L, R));
				}
				if(bestL < oo || bestR < oo) {
					ans = X;
				}
			}
		}
		swap(dp, save_dp);
		for(int i = 0; i < N; ++i) {
			for(int j = 0; j < N; ++j) {
				for(int k = 0; k < 2; ++k) {
					dp[i][j][k] = oo;
				}
			}
		}
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8268 KB Output is correct
2 Correct 12 ms 8268 KB Output is correct
3 Correct 17 ms 8268 KB Output is correct
4 Correct 12 ms 8268 KB Output is correct
5 Correct 15 ms 8308 KB Output is correct
6 Correct 20 ms 8312 KB Output is correct
7 Correct 13 ms 8312 KB Output is correct
8 Correct 14 ms 8308 KB Output is correct
9 Correct 17 ms 8268 KB Output is correct
10 Correct 6 ms 8268 KB Output is correct
11 Correct 6 ms 8268 KB Output is correct
12 Correct 16 ms 8312 KB Output is correct
13 Correct 16 ms 8312 KB Output is correct
14 Correct 11 ms 8268 KB Output is correct
15 Correct 12 ms 8312 KB Output is correct
16 Correct 16 ms 8268 KB Output is correct
17 Correct 16 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8268 KB Output is correct
2 Correct 12 ms 8268 KB Output is correct
3 Correct 17 ms 8268 KB Output is correct
4 Correct 12 ms 8268 KB Output is correct
5 Correct 15 ms 8308 KB Output is correct
6 Correct 20 ms 8312 KB Output is correct
7 Correct 13 ms 8312 KB Output is correct
8 Correct 14 ms 8308 KB Output is correct
9 Correct 17 ms 8268 KB Output is correct
10 Correct 6 ms 8268 KB Output is correct
11 Correct 6 ms 8268 KB Output is correct
12 Correct 16 ms 8312 KB Output is correct
13 Correct 16 ms 8312 KB Output is correct
14 Correct 11 ms 8268 KB Output is correct
15 Correct 12 ms 8312 KB Output is correct
16 Correct 16 ms 8268 KB Output is correct
17 Correct 16 ms 8268 KB Output is correct
18 Correct 19 ms 8396 KB Output is correct
19 Correct 14 ms 8312 KB Output is correct
20 Correct 16 ms 8316 KB Output is correct
21 Correct 19 ms 8264 KB Output is correct
22 Correct 14 ms 8308 KB Output is correct
23 Correct 18 ms 8268 KB Output is correct
24 Correct 17 ms 8308 KB Output is correct
25 Correct 20 ms 8268 KB Output is correct
26 Correct 22 ms 8308 KB Output is correct
27 Correct 14 ms 8308 KB Output is correct
28 Correct 14 ms 8308 KB Output is correct
29 Correct 20 ms 8316 KB Output is correct
30 Correct 19 ms 8312 KB Output is correct
31 Correct 18 ms 8308 KB Output is correct
32 Correct 17 ms 8268 KB Output is correct
33 Correct 20 ms 8268 KB Output is correct
34 Correct 20 ms 8312 KB Output is correct
35 Correct 23 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8268 KB Output is correct
2 Correct 12 ms 8268 KB Output is correct
3 Correct 17 ms 8268 KB Output is correct
4 Correct 12 ms 8268 KB Output is correct
5 Correct 15 ms 8308 KB Output is correct
6 Correct 20 ms 8312 KB Output is correct
7 Correct 13 ms 8312 KB Output is correct
8 Correct 14 ms 8308 KB Output is correct
9 Correct 17 ms 8268 KB Output is correct
10 Correct 6 ms 8268 KB Output is correct
11 Correct 6 ms 8268 KB Output is correct
12 Correct 16 ms 8312 KB Output is correct
13 Correct 16 ms 8312 KB Output is correct
14 Correct 11 ms 8268 KB Output is correct
15 Correct 12 ms 8312 KB Output is correct
16 Correct 16 ms 8268 KB Output is correct
17 Correct 16 ms 8268 KB Output is correct
18 Correct 247 ms 8288 KB Output is correct
19 Correct 164 ms 8288 KB Output is correct
20 Correct 144 ms 8296 KB Output is correct
21 Correct 165 ms 8268 KB Output is correct
22 Correct 189 ms 8292 KB Output is correct
23 Correct 104 ms 8268 KB Output is correct
24 Correct 91 ms 8288 KB Output is correct
25 Correct 106 ms 8288 KB Output is correct
26 Correct 65 ms 8292 KB Output is correct
27 Correct 106 ms 8268 KB Output is correct
28 Correct 83 ms 8288 KB Output is correct
29 Correct 102 ms 8388 KB Output is correct
30 Correct 94 ms 8288 KB Output is correct
31 Correct 101 ms 8312 KB Output is correct
32 Correct 87 ms 8268 KB Output is correct
33 Correct 102 ms 8268 KB Output is correct
34 Correct 57 ms 8296 KB Output is correct
35 Correct 108 ms 8300 KB Output is correct
36 Correct 63 ms 8264 KB Output is correct
37 Correct 103 ms 8268 KB Output is correct
38 Correct 72 ms 8272 KB Output is correct
39 Correct 100 ms 8268 KB Output is correct
40 Correct 81 ms 8388 KB Output is correct
41 Correct 281 ms 8268 KB Output is correct
42 Correct 239 ms 8392 KB Output is correct
43 Correct 259 ms 8300 KB Output is correct
44 Correct 206 ms 8268 KB Output is correct
45 Correct 278 ms 8292 KB Output is correct
46 Correct 213 ms 8388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8268 KB Output is correct
2 Correct 12 ms 8268 KB Output is correct
3 Correct 17 ms 8268 KB Output is correct
4 Correct 12 ms 8268 KB Output is correct
5 Correct 15 ms 8308 KB Output is correct
6 Correct 20 ms 8312 KB Output is correct
7 Correct 13 ms 8312 KB Output is correct
8 Correct 14 ms 8308 KB Output is correct
9 Correct 17 ms 8268 KB Output is correct
10 Correct 6 ms 8268 KB Output is correct
11 Correct 6 ms 8268 KB Output is correct
12 Correct 16 ms 8312 KB Output is correct
13 Correct 16 ms 8312 KB Output is correct
14 Correct 11 ms 8268 KB Output is correct
15 Correct 12 ms 8312 KB Output is correct
16 Correct 16 ms 8268 KB Output is correct
17 Correct 16 ms 8268 KB Output is correct
18 Correct 19 ms 8396 KB Output is correct
19 Correct 14 ms 8312 KB Output is correct
20 Correct 16 ms 8316 KB Output is correct
21 Correct 19 ms 8264 KB Output is correct
22 Correct 14 ms 8308 KB Output is correct
23 Correct 18 ms 8268 KB Output is correct
24 Correct 17 ms 8308 KB Output is correct
25 Correct 20 ms 8268 KB Output is correct
26 Correct 22 ms 8308 KB Output is correct
27 Correct 14 ms 8308 KB Output is correct
28 Correct 14 ms 8308 KB Output is correct
29 Correct 20 ms 8316 KB Output is correct
30 Correct 19 ms 8312 KB Output is correct
31 Correct 18 ms 8308 KB Output is correct
32 Correct 17 ms 8268 KB Output is correct
33 Correct 20 ms 8268 KB Output is correct
34 Correct 20 ms 8312 KB Output is correct
35 Correct 23 ms 8268 KB Output is correct
36 Correct 247 ms 8288 KB Output is correct
37 Correct 164 ms 8288 KB Output is correct
38 Correct 144 ms 8296 KB Output is correct
39 Correct 165 ms 8268 KB Output is correct
40 Correct 189 ms 8292 KB Output is correct
41 Correct 104 ms 8268 KB Output is correct
42 Correct 91 ms 8288 KB Output is correct
43 Correct 106 ms 8288 KB Output is correct
44 Correct 65 ms 8292 KB Output is correct
45 Correct 106 ms 8268 KB Output is correct
46 Correct 83 ms 8288 KB Output is correct
47 Correct 102 ms 8388 KB Output is correct
48 Correct 94 ms 8288 KB Output is correct
49 Correct 101 ms 8312 KB Output is correct
50 Correct 87 ms 8268 KB Output is correct
51 Correct 102 ms 8268 KB Output is correct
52 Correct 57 ms 8296 KB Output is correct
53 Correct 108 ms 8300 KB Output is correct
54 Correct 63 ms 8264 KB Output is correct
55 Correct 103 ms 8268 KB Output is correct
56 Correct 72 ms 8272 KB Output is correct
57 Correct 100 ms 8268 KB Output is correct
58 Correct 81 ms 8388 KB Output is correct
59 Correct 281 ms 8268 KB Output is correct
60 Correct 239 ms 8392 KB Output is correct
61 Correct 259 ms 8300 KB Output is correct
62 Correct 206 ms 8268 KB Output is correct
63 Correct 278 ms 8292 KB Output is correct
64 Correct 213 ms 8388 KB Output is correct
65 Correct 280 ms 8308 KB Output is correct
66 Correct 238 ms 8300 KB Output is correct
67 Correct 232 ms 8292 KB Output is correct
68 Correct 224 ms 8292 KB Output is correct
69 Correct 254 ms 8312 KB Output is correct
70 Correct 252 ms 8268 KB Output is correct
71 Correct 247 ms 8308 KB Output is correct
72 Correct 249 ms 8296 KB Output is correct
73 Correct 252 ms 8268 KB Output is correct
74 Correct 229 ms 8296 KB Output is correct
75 Correct 235 ms 8304 KB Output is correct
76 Correct 261 ms 8296 KB Output is correct
77 Correct 286 ms 8292 KB Output is correct
78 Correct 236 ms 8268 KB Output is correct
79 Correct 282 ms 8292 KB Output is correct
80 Correct 271 ms 8320 KB Output is correct
81 Correct 251 ms 8296 KB Output is correct
82 Correct 291 ms 8296 KB Output is correct
83 Correct 313 ms 8300 KB Output is correct
84 Correct 287 ms 8264 KB Output is correct
85 Correct 289 ms 8320 KB Output is correct
86 Correct 297 ms 8292 KB Output is correct
87 Correct 259 ms 8268 KB Output is correct
88 Correct 304 ms 8292 KB Output is correct
89 Correct 295 ms 8292 KB Output is correct
90 Correct 245 ms 8296 KB Output is correct
91 Correct 280 ms 8300 KB Output is correct
92 Correct 287 ms 8388 KB Output is correct
93 Correct 295 ms 8292 KB Output is correct