답안 #767524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767524 2023-06-26T19:59:37 Z NK_ Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
457 ms 448848 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define sz(x) signed(x.size())
#define int long long

template<class T> using V = vector<T>;

const int INF = 1e15+10;


signed main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, L; cin >> N >> L;
	V<int> A(N), T(N);

	for(auto& x : A) cin >> x;
	for(auto& x : T) cin >> x;

	A.insert(begin(A), 0); T.insert(begin(T), -1);
	A.push_back(0); T.push_back(-1);

	// for(auto& x : A) cout << x << " ";
	// cout << endl;
	// for(auto& x : T) cout << x << " ";
	// cout << endl;

	// dp[SFX][PFX][K][2] = min time

	V<V<V<V<int>>>> dp(N + 1, V<V<V<int>>>(N + 1, V<V<int>>(N + 1, V<int>(2, INF))));
	// int dp[N + 1][N + 1][N + 1][2];
	// for(int i = 0; i <= N; i++) for(int j = 0; j <= N; j++) {
	// 	for(int k = 0; k <= N; k++) for(int l = 0; l < 2; l++) {
	// 		dp[i][j][k][l] = INF;
	// 	}
	// }

	int ans = 0;
	dp[0][0][0][0] = 0;
	for(int w = 0; w <= N; w++) {
		for(int s = 0; s <= N; s++) {
			int p = w - s; if (p < 0) continue;

			for(int k = 0; k <= N; k++) for(int x = 0; x < 2; x++) if (dp[s][p][k][x] != INF) {
				// cout << s << " " << p << " " << k << " " << x << " -> " << dp[s][p][k][x] << endl;
				ans = max(ans, k);
				
				int i = (x == 0 ? sz(A) - 1 - s : p);
				if (w+1 <= N) {
					// move left
					{
						int ni = (sz(A) - 1 - s - 1); 
						// cout << ni << endl;
						int nt = dp[s][p][k][x] + min(L - abs(A[i] - A[ni]), abs(A[i] - A[ni]));
						// cout << "LEFT: " << nt << endl;
						int get = (T[ni] >= nt);
						dp[s+1][p][k + get][0] = min(dp[s+1][p][k + get][0], nt);
					}


					// move right
					{
						int ni = p + 1;
						// cout << ni << endl;
						int nt = dp[s][p][k][x] + min(L - abs(A[i] - A[ni]), abs(A[i] - A[ni]));
						// cout << "RIGHT: " << nt << endl;
						int get = (T[ni] >= nt);
						dp[s][p+1][k + get][1] = min(dp[s][p+1][k + get][1], nt);
					}
				}
			}
		}
	}

	cout << ans << nl;
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 291 ms 322864 KB Output is correct
19 Correct 152 ms 152524 KB Output is correct
20 Correct 60 ms 59444 KB Output is correct
21 Correct 132 ms 139888 KB Output is correct
22 Correct 188 ms 206436 KB Output is correct
23 Correct 48 ms 46656 KB Output is correct
24 Correct 33 ms 32212 KB Output is correct
25 Correct 46 ms 45088 KB Output is correct
26 Correct 10 ms 10708 KB Output is correct
27 Correct 49 ms 48028 KB Output is correct
28 Correct 30 ms 28968 KB Output is correct
29 Correct 50 ms 49632 KB Output is correct
30 Correct 35 ms 34556 KB Output is correct
31 Correct 46 ms 45056 KB Output is correct
32 Correct 18 ms 17108 KB Output is correct
33 Correct 46 ms 45132 KB Output is correct
34 Correct 9 ms 9684 KB Output is correct
35 Correct 59 ms 43724 KB Output is correct
36 Correct 14 ms 14292 KB Output is correct
37 Correct 48 ms 48084 KB Output is correct
38 Correct 21 ms 19540 KB Output is correct
39 Correct 50 ms 51020 KB Output is correct
40 Correct 24 ms 23048 KB Output is correct
41 Correct 406 ms 442452 KB Output is correct
42 Correct 213 ms 244436 KB Output is correct
43 Correct 390 ms 442444 KB Output is correct
44 Correct 218 ms 239980 KB Output is correct
45 Correct 407 ms 442448 KB Output is correct
46 Correct 215 ms 244428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 291 ms 322864 KB Output is correct
37 Correct 152 ms 152524 KB Output is correct
38 Correct 60 ms 59444 KB Output is correct
39 Correct 132 ms 139888 KB Output is correct
40 Correct 188 ms 206436 KB Output is correct
41 Correct 48 ms 46656 KB Output is correct
42 Correct 33 ms 32212 KB Output is correct
43 Correct 46 ms 45088 KB Output is correct
44 Correct 10 ms 10708 KB Output is correct
45 Correct 49 ms 48028 KB Output is correct
46 Correct 30 ms 28968 KB Output is correct
47 Correct 50 ms 49632 KB Output is correct
48 Correct 35 ms 34556 KB Output is correct
49 Correct 46 ms 45056 KB Output is correct
50 Correct 18 ms 17108 KB Output is correct
51 Correct 46 ms 45132 KB Output is correct
52 Correct 9 ms 9684 KB Output is correct
53 Correct 59 ms 43724 KB Output is correct
54 Correct 14 ms 14292 KB Output is correct
55 Correct 48 ms 48084 KB Output is correct
56 Correct 21 ms 19540 KB Output is correct
57 Correct 50 ms 51020 KB Output is correct
58 Correct 24 ms 23048 KB Output is correct
59 Correct 406 ms 442452 KB Output is correct
60 Correct 213 ms 244436 KB Output is correct
61 Correct 390 ms 442444 KB Output is correct
62 Correct 218 ms 239980 KB Output is correct
63 Correct 407 ms 442448 KB Output is correct
64 Correct 215 ms 244428 KB Output is correct
65 Correct 334 ms 379560 KB Output is correct
66 Correct 301 ms 333772 KB Output is correct
67 Correct 295 ms 312388 KB Output is correct
68 Correct 253 ms 276832 KB Output is correct
69 Correct 337 ms 373316 KB Output is correct
70 Correct 457 ms 350216 KB Output is correct
71 Correct 336 ms 356300 KB Output is correct
72 Correct 328 ms 361576 KB Output is correct
73 Correct 297 ms 322892 KB Output is correct
74 Correct 271 ms 291864 KB Output is correct
75 Correct 301 ms 338948 KB Output is correct
76 Correct 389 ms 416588 KB Output is correct
77 Correct 377 ms 416520 KB Output is correct
78 Correct 258 ms 282012 KB Output is correct
79 Correct 267 ms 296632 KB Output is correct
80 Correct 360 ms 403884 KB Output is correct
81 Correct 288 ms 301916 KB Output is correct
82 Correct 301 ms 328008 KB Output is correct
83 Correct 397 ms 442572 KB Output is correct
84 Correct 303 ms 350120 KB Output is correct
85 Correct 350 ms 397396 KB Output is correct
86 Correct 337 ms 385276 KB Output is correct
87 Correct 305 ms 338928 KB Output is correct
88 Correct 428 ms 448772 KB Output is correct
89 Correct 401 ms 448776 KB Output is correct
90 Correct 301 ms 344952 KB Output is correct
91 Correct 450 ms 448848 KB Output is correct
92 Correct 406 ms 448716 KB Output is correct
93 Correct 371 ms 435560 KB Output is correct