Submission #201025

# Submission time Handle Problem Language Result Execution time Memory
201025 2020-02-09T06:26:16 Z gs14004 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
357 ms 516728 KB
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 404;

int n, l;
pi a[MAXN];

lint dp[MAXN][MAXN][MAXN / 2][2];

lint dist(int x, int y){ return abs(a[x].first - a[y].first); }

int main(){
	cin >> n >> l;
	for(int i=1; i<=n; i++) cin >> a[i+n].first;
	for(int i=1; i<=n; i++) cin >> a[i+n].second;
	for(int i=0; i<n; i++) a[i] = pi(a[i+n+1].first - l, a[i+n+1].second);
	a[n] = pi(0, 0);
	memset(dp, 0x3f, sizeof(dp));
	dp[n][n][0][0] = dp[n][n][0][1] = 0;
	int dap = 0;
	for(int i=1; i<=n; i++){
		for(int j=0; j+i<=2*n; j++){
			for(int k=0; k<=i; k++){
				dp[j][j + i][k][0] = min(dp[j+1][j+i][k][0] + dist(j+1, j), dp[j+1][j+i][k][1] + dist(j+i, j));
				if(k > 0 && dp[j + 1][j + i][k - 1][0] + dist(j+1, j) <= a[j].second){
					dp[j][j + i][k][0] = min(dp[j][j + i][k][0], dp[j+1][j+i][k-1][0] + dist(j+1, j));
				}
				if(k > 0 && dp[j + 1][j + i][k - 1][1] + dist(j+i, j) <= a[j].second){
					dp[j][j + i][k][0] = min(dp[j][j + i][k][0], dp[j+1][j+i][k-1][1] + dist(j+i, j));
				}
				dp[j][j + i][k][1] = min(dp[j][j+i-1][k][1] + dist(j+i-1, j+i), dp[j][j+i-1][k][0] + dist(j+i, j));
				if(k > 0 && dp[j][j+i-1][k-1][0] + dist(j+i, j) <= a[j+i].second){
					dp[j][j + i][k][1] = min(dp[j][j + i][k][1], dp[j][j+i-1][k-1][0] + dist(j+i, j));
				}
				if(k > 0 && dp[j][j+i-1][k-1][1] + dist(j+i, j+i-1) <= a[j+i].second){
					dp[j][j + i][k][1] = min(dp[j][j + i][k][1], dp[j][j+i-1][k-1][1] + dist(j+i, j+i-1));
				}
				if(dp[j][j+i][k][0] <= 1e10 + 100) dap = max(dap, k);
				if(dp[j][j+i][k][1] <= 1e10 + 100) dap = max(dap, k);
			}
		}
	}
	cout << dap << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 279 ms 516472 KB Output is correct
2 Correct 281 ms 516600 KB Output is correct
3 Correct 272 ms 516472 KB Output is correct
4 Correct 276 ms 516612 KB Output is correct
5 Correct 275 ms 516472 KB Output is correct
6 Correct 272 ms 516472 KB Output is correct
7 Correct 279 ms 516612 KB Output is correct
8 Correct 266 ms 516472 KB Output is correct
9 Correct 276 ms 516624 KB Output is correct
10 Correct 273 ms 516472 KB Output is correct
11 Correct 275 ms 516472 KB Output is correct
12 Correct 280 ms 516476 KB Output is correct
13 Correct 265 ms 516472 KB Output is correct
14 Correct 275 ms 516460 KB Output is correct
15 Correct 269 ms 516472 KB Output is correct
16 Correct 293 ms 516600 KB Output is correct
17 Correct 279 ms 516472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 516472 KB Output is correct
2 Correct 281 ms 516600 KB Output is correct
3 Correct 272 ms 516472 KB Output is correct
4 Correct 276 ms 516612 KB Output is correct
5 Correct 275 ms 516472 KB Output is correct
6 Correct 272 ms 516472 KB Output is correct
7 Correct 279 ms 516612 KB Output is correct
8 Correct 266 ms 516472 KB Output is correct
9 Correct 276 ms 516624 KB Output is correct
10 Correct 273 ms 516472 KB Output is correct
11 Correct 275 ms 516472 KB Output is correct
12 Correct 280 ms 516476 KB Output is correct
13 Correct 265 ms 516472 KB Output is correct
14 Correct 275 ms 516460 KB Output is correct
15 Correct 269 ms 516472 KB Output is correct
16 Correct 293 ms 516600 KB Output is correct
17 Correct 279 ms 516472 KB Output is correct
18 Correct 283 ms 516472 KB Output is correct
19 Correct 277 ms 516632 KB Output is correct
20 Correct 281 ms 516688 KB Output is correct
21 Correct 270 ms 516472 KB Output is correct
22 Correct 282 ms 516472 KB Output is correct
23 Correct 279 ms 516476 KB Output is correct
24 Correct 276 ms 516472 KB Output is correct
25 Correct 285 ms 516472 KB Output is correct
26 Correct 275 ms 516472 KB Output is correct
27 Correct 275 ms 516600 KB Output is correct
28 Correct 284 ms 516472 KB Output is correct
29 Correct 274 ms 516600 KB Output is correct
30 Correct 277 ms 516472 KB Output is correct
31 Correct 274 ms 516480 KB Output is correct
32 Correct 275 ms 516672 KB Output is correct
33 Correct 284 ms 516472 KB Output is correct
34 Correct 276 ms 516596 KB Output is correct
35 Correct 288 ms 516476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 516472 KB Output is correct
2 Correct 281 ms 516600 KB Output is correct
3 Correct 272 ms 516472 KB Output is correct
4 Correct 276 ms 516612 KB Output is correct
5 Correct 275 ms 516472 KB Output is correct
6 Correct 272 ms 516472 KB Output is correct
7 Correct 279 ms 516612 KB Output is correct
8 Correct 266 ms 516472 KB Output is correct
9 Correct 276 ms 516624 KB Output is correct
10 Correct 273 ms 516472 KB Output is correct
11 Correct 275 ms 516472 KB Output is correct
12 Correct 280 ms 516476 KB Output is correct
13 Correct 265 ms 516472 KB Output is correct
14 Correct 275 ms 516460 KB Output is correct
15 Correct 269 ms 516472 KB Output is correct
16 Correct 293 ms 516600 KB Output is correct
17 Correct 279 ms 516472 KB Output is correct
18 Correct 326 ms 516472 KB Output is correct
19 Correct 296 ms 516472 KB Output is correct
20 Correct 292 ms 516472 KB Output is correct
21 Correct 306 ms 516504 KB Output is correct
22 Correct 298 ms 516448 KB Output is correct
23 Correct 289 ms 516600 KB Output is correct
24 Correct 298 ms 516472 KB Output is correct
25 Correct 291 ms 516472 KB Output is correct
26 Correct 288 ms 516468 KB Output is correct
27 Correct 316 ms 516472 KB Output is correct
28 Correct 310 ms 516504 KB Output is correct
29 Correct 296 ms 516492 KB Output is correct
30 Correct 296 ms 516472 KB Output is correct
31 Correct 293 ms 516564 KB Output is correct
32 Correct 282 ms 516472 KB Output is correct
33 Correct 293 ms 516564 KB Output is correct
34 Correct 281 ms 516472 KB Output is correct
35 Correct 281 ms 516472 KB Output is correct
36 Correct 291 ms 516600 KB Output is correct
37 Correct 287 ms 516472 KB Output is correct
38 Correct 290 ms 516600 KB Output is correct
39 Correct 305 ms 516472 KB Output is correct
40 Correct 288 ms 516728 KB Output is correct
41 Correct 342 ms 516472 KB Output is correct
42 Correct 304 ms 516600 KB Output is correct
43 Correct 320 ms 516476 KB Output is correct
44 Correct 303 ms 516472 KB Output is correct
45 Correct 335 ms 516728 KB Output is correct
46 Correct 299 ms 516472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 516472 KB Output is correct
2 Correct 281 ms 516600 KB Output is correct
3 Correct 272 ms 516472 KB Output is correct
4 Correct 276 ms 516612 KB Output is correct
5 Correct 275 ms 516472 KB Output is correct
6 Correct 272 ms 516472 KB Output is correct
7 Correct 279 ms 516612 KB Output is correct
8 Correct 266 ms 516472 KB Output is correct
9 Correct 276 ms 516624 KB Output is correct
10 Correct 273 ms 516472 KB Output is correct
11 Correct 275 ms 516472 KB Output is correct
12 Correct 280 ms 516476 KB Output is correct
13 Correct 265 ms 516472 KB Output is correct
14 Correct 275 ms 516460 KB Output is correct
15 Correct 269 ms 516472 KB Output is correct
16 Correct 293 ms 516600 KB Output is correct
17 Correct 279 ms 516472 KB Output is correct
18 Correct 283 ms 516472 KB Output is correct
19 Correct 277 ms 516632 KB Output is correct
20 Correct 281 ms 516688 KB Output is correct
21 Correct 270 ms 516472 KB Output is correct
22 Correct 282 ms 516472 KB Output is correct
23 Correct 279 ms 516476 KB Output is correct
24 Correct 276 ms 516472 KB Output is correct
25 Correct 285 ms 516472 KB Output is correct
26 Correct 275 ms 516472 KB Output is correct
27 Correct 275 ms 516600 KB Output is correct
28 Correct 284 ms 516472 KB Output is correct
29 Correct 274 ms 516600 KB Output is correct
30 Correct 277 ms 516472 KB Output is correct
31 Correct 274 ms 516480 KB Output is correct
32 Correct 275 ms 516672 KB Output is correct
33 Correct 284 ms 516472 KB Output is correct
34 Correct 276 ms 516596 KB Output is correct
35 Correct 288 ms 516476 KB Output is correct
36 Correct 326 ms 516472 KB Output is correct
37 Correct 296 ms 516472 KB Output is correct
38 Correct 292 ms 516472 KB Output is correct
39 Correct 306 ms 516504 KB Output is correct
40 Correct 298 ms 516448 KB Output is correct
41 Correct 289 ms 516600 KB Output is correct
42 Correct 298 ms 516472 KB Output is correct
43 Correct 291 ms 516472 KB Output is correct
44 Correct 288 ms 516468 KB Output is correct
45 Correct 316 ms 516472 KB Output is correct
46 Correct 310 ms 516504 KB Output is correct
47 Correct 296 ms 516492 KB Output is correct
48 Correct 296 ms 516472 KB Output is correct
49 Correct 293 ms 516564 KB Output is correct
50 Correct 282 ms 516472 KB Output is correct
51 Correct 293 ms 516564 KB Output is correct
52 Correct 281 ms 516472 KB Output is correct
53 Correct 281 ms 516472 KB Output is correct
54 Correct 291 ms 516600 KB Output is correct
55 Correct 287 ms 516472 KB Output is correct
56 Correct 290 ms 516600 KB Output is correct
57 Correct 305 ms 516472 KB Output is correct
58 Correct 288 ms 516728 KB Output is correct
59 Correct 342 ms 516472 KB Output is correct
60 Correct 304 ms 516600 KB Output is correct
61 Correct 320 ms 516476 KB Output is correct
62 Correct 303 ms 516472 KB Output is correct
63 Correct 335 ms 516728 KB Output is correct
64 Correct 299 ms 516472 KB Output is correct
65 Correct 329 ms 516700 KB Output is correct
66 Correct 309 ms 516472 KB Output is correct
67 Correct 321 ms 516544 KB Output is correct
68 Correct 330 ms 516472 KB Output is correct
69 Correct 319 ms 516600 KB Output is correct
70 Correct 319 ms 516472 KB Output is correct
71 Correct 320 ms 516472 KB Output is correct
72 Correct 321 ms 516600 KB Output is correct
73 Correct 331 ms 516472 KB Output is correct
74 Correct 311 ms 516728 KB Output is correct
75 Correct 311 ms 516472 KB Output is correct
76 Correct 350 ms 516520 KB Output is correct
77 Correct 311 ms 516472 KB Output is correct
78 Correct 319 ms 516524 KB Output is correct
79 Correct 318 ms 516448 KB Output is correct
80 Correct 332 ms 516448 KB Output is correct
81 Correct 335 ms 516408 KB Output is correct
82 Correct 352 ms 516476 KB Output is correct
83 Correct 337 ms 516488 KB Output is correct
84 Correct 357 ms 516472 KB Output is correct
85 Correct 347 ms 516600 KB Output is correct
86 Correct 351 ms 516472 KB Output is correct
87 Correct 355 ms 516472 KB Output is correct
88 Correct 319 ms 516572 KB Output is correct
89 Correct 321 ms 516600 KB Output is correct
90 Correct 313 ms 516600 KB Output is correct
91 Correct 319 ms 516472 KB Output is correct
92 Correct 318 ms 516472 KB Output is correct
93 Correct 316 ms 516472 KB Output is correct