# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
361216 | 2021-01-28T17:58:34 Z | Sparky_09 | Collecting Stamps 3 (JOI20_ho_t3) | C++17 | 131 ms | 134636 KB |
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; void usaco(string s){ freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } const ll inf = 1e18+9; ll n, l; ll a[209]; ll b[209]; ll dp[209][209][209][2]; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif cin >> n >> l; for(ll i = 1; i <= n; ++i) cin >> a[i]; for(ll i = 1; i <= n; ++i) cin >> b[i]; for(ll i = 0; i <= n+1; ++i) for(ll j = 0; j <= n+1; ++j) for(ll k = 0; k <= n+1; ++k) for(ll m = 0; m < 2; ++m) dp[i][j][k][m] = inf; a[n+1] = l; dp[0][n+1][0][0] = dp[0][n+1][0][1] = 0; ll ans = 0; for(ll i = 0; i <= n+1; ++i) for(ll j = n+1; j >= 0; --j) for(ll k = 0; k <= n+1; ++k) for(ll st = 0; st < 2; ++st){ if(dp[i][j][k][st] == inf) continue; ans = max(ans, k); if(i+1 >= j) continue; if(st == 0){ ll t1 = dp[i][j][k][st] + a[i+1] - a[i]; if(t1 <= b[i+1]) dp[i+1][j][k+1][st] = min(dp[i+1][j][k+1][st], t1); else dp[i+1][j][k][st] = min(dp[i+1][j][k][st], t1); ll t2 = dp[i][j][k][st] + a[i] + l-a[j-1]; if(t2 <= b[j-1]) dp[i][j-1][k+1][st^1] = min(dp[i][j-1][k+1][st^1], t2); else dp[i][j-1][k][st^1] = min(dp[i][j-1][k][st^1], t2); } else{ ll t1 = dp[i][j][k][st] + a[i+1] + l-a[j]; if(t1 <= b[i+1]) dp[i+1][j][k+1][st^1] = min(dp[i+1][j][k+1][st^1], t1); else dp[i+1][j][k][st^1] = min(dp[i+1][j][k][st^1], t1); ll t2 = dp[i][j][k][st] + a[j] - a[j-1]; if(t2 <= b[j-1]) dp[i][j-1][k+1][st] = min(dp[i][j-1][k+1][st], t2); else dp[i][j-1][k][st] = min(dp[i][j-1][k][st], t2); } } cout << ans << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 496 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 620 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 1004 KB | Output is correct |
7 | Correct | 1 ms | 748 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 1004 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 1004 KB | Output is correct |
13 | Correct | 1 ms | 1004 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 1004 KB | Output is correct |
17 | Correct | 1 ms | 1004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 496 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 620 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 1004 KB | Output is correct |
7 | Correct | 1 ms | 748 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 1004 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 1004 KB | Output is correct |
13 | Correct | 1 ms | 1004 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 1004 KB | Output is correct |
17 | Correct | 1 ms | 1004 KB | Output is correct |
18 | Correct | 1 ms | 1260 KB | Output is correct |
19 | Correct | 1 ms | 824 KB | Output is correct |
20 | Correct | 1 ms | 1004 KB | Output is correct |
21 | Correct | 1 ms | 1260 KB | Output is correct |
22 | Correct | 1 ms | 780 KB | Output is correct |
23 | Correct | 1 ms | 1388 KB | Output is correct |
24 | Correct | 1 ms | 1132 KB | Output is correct |
25 | Correct | 1 ms | 1260 KB | Output is correct |
26 | Correct | 1 ms | 1260 KB | Output is correct |
27 | Correct | 1 ms | 748 KB | Output is correct |
28 | Correct | 1 ms | 748 KB | Output is correct |
29 | Correct | 1 ms | 1388 KB | Output is correct |
30 | Correct | 1 ms | 1388 KB | Output is correct |
31 | Correct | 1 ms | 1260 KB | Output is correct |
32 | Correct | 1 ms | 1132 KB | Output is correct |
33 | Correct | 1 ms | 1280 KB | Output is correct |
34 | Correct | 1 ms | 1388 KB | Output is correct |
35 | Correct | 1 ms | 1388 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 496 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 620 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 1004 KB | Output is correct |
7 | Correct | 1 ms | 748 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 1004 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 1004 KB | Output is correct |
13 | Correct | 1 ms | 1004 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 1004 KB | Output is correct |
17 | Correct | 1 ms | 1004 KB | Output is correct |
18 | Correct | 95 ms | 108264 KB | Output is correct |
19 | Correct | 55 ms | 65900 KB | Output is correct |
20 | Correct | 26 ms | 35308 KB | Output is correct |
21 | Correct | 52 ms | 62188 KB | Output is correct |
22 | Correct | 67 ms | 80492 KB | Output is correct |
23 | Correct | 23 ms | 30188 KB | Output is correct |
24 | Correct | 17 ms | 23660 KB | Output is correct |
25 | Correct | 23 ms | 29548 KB | Output is correct |
26 | Correct | 8 ms | 11500 KB | Output is correct |
27 | Correct | 23 ms | 30828 KB | Output is correct |
28 | Correct | 16 ms | 21996 KB | Output is correct |
29 | Correct | 24 ms | 31468 KB | Output is correct |
30 | Correct | 17 ms | 24812 KB | Output is correct |
31 | Correct | 26 ms | 29548 KB | Output is correct |
32 | Correct | 11 ms | 15596 KB | Output is correct |
33 | Correct | 22 ms | 29676 KB | Output is correct |
34 | Correct | 8 ms | 10732 KB | Output is correct |
35 | Correct | 20 ms | 28908 KB | Output is correct |
36 | Correct | 10 ms | 13932 KB | Output is correct |
37 | Correct | 23 ms | 30844 KB | Output is correct |
38 | Correct | 12 ms | 17004 KB | Output is correct |
39 | Correct | 23 ms | 32108 KB | Output is correct |
40 | Correct | 13 ms | 18924 KB | Output is correct |
41 | Correct | 131 ms | 133484 KB | Output is correct |
42 | Correct | 71 ms | 89964 KB | Output is correct |
43 | Correct | 122 ms | 133460 KB | Output is correct |
44 | Correct | 70 ms | 88960 KB | Output is correct |
45 | Correct | 120 ms | 133356 KB | Output is correct |
46 | Correct | 72 ms | 90092 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 496 KB | Output is correct |
2 | Correct | 1 ms | 492 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 620 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 1004 KB | Output is correct |
7 | Correct | 1 ms | 748 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 1004 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 1004 KB | Output is correct |
13 | Correct | 1 ms | 1004 KB | Output is correct |
14 | Correct | 1 ms | 620 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 1004 KB | Output is correct |
17 | Correct | 1 ms | 1004 KB | Output is correct |
18 | Correct | 1 ms | 1260 KB | Output is correct |
19 | Correct | 1 ms | 824 KB | Output is correct |
20 | Correct | 1 ms | 1004 KB | Output is correct |
21 | Correct | 1 ms | 1260 KB | Output is correct |
22 | Correct | 1 ms | 780 KB | Output is correct |
23 | Correct | 1 ms | 1388 KB | Output is correct |
24 | Correct | 1 ms | 1132 KB | Output is correct |
25 | Correct | 1 ms | 1260 KB | Output is correct |
26 | Correct | 1 ms | 1260 KB | Output is correct |
27 | Correct | 1 ms | 748 KB | Output is correct |
28 | Correct | 1 ms | 748 KB | Output is correct |
29 | Correct | 1 ms | 1388 KB | Output is correct |
30 | Correct | 1 ms | 1388 KB | Output is correct |
31 | Correct | 1 ms | 1260 KB | Output is correct |
32 | Correct | 1 ms | 1132 KB | Output is correct |
33 | Correct | 1 ms | 1280 KB | Output is correct |
34 | Correct | 1 ms | 1388 KB | Output is correct |
35 | Correct | 1 ms | 1388 KB | Output is correct |
36 | Correct | 95 ms | 108264 KB | Output is correct |
37 | Correct | 55 ms | 65900 KB | Output is correct |
38 | Correct | 26 ms | 35308 KB | Output is correct |
39 | Correct | 52 ms | 62188 KB | Output is correct |
40 | Correct | 67 ms | 80492 KB | Output is correct |
41 | Correct | 23 ms | 30188 KB | Output is correct |
42 | Correct | 17 ms | 23660 KB | Output is correct |
43 | Correct | 23 ms | 29548 KB | Output is correct |
44 | Correct | 8 ms | 11500 KB | Output is correct |
45 | Correct | 23 ms | 30828 KB | Output is correct |
46 | Correct | 16 ms | 21996 KB | Output is correct |
47 | Correct | 24 ms | 31468 KB | Output is correct |
48 | Correct | 17 ms | 24812 KB | Output is correct |
49 | Correct | 26 ms | 29548 KB | Output is correct |
50 | Correct | 11 ms | 15596 KB | Output is correct |
51 | Correct | 22 ms | 29676 KB | Output is correct |
52 | Correct | 8 ms | 10732 KB | Output is correct |
53 | Correct | 20 ms | 28908 KB | Output is correct |
54 | Correct | 10 ms | 13932 KB | Output is correct |
55 | Correct | 23 ms | 30844 KB | Output is correct |
56 | Correct | 12 ms | 17004 KB | Output is correct |
57 | Correct | 23 ms | 32108 KB | Output is correct |
58 | Correct | 13 ms | 18924 KB | Output is correct |
59 | Correct | 131 ms | 133484 KB | Output is correct |
60 | Correct | 71 ms | 89964 KB | Output is correct |
61 | Correct | 122 ms | 133460 KB | Output is correct |
62 | Correct | 70 ms | 88960 KB | Output is correct |
63 | Correct | 120 ms | 133356 KB | Output is correct |
64 | Correct | 72 ms | 90092 KB | Output is correct |
65 | Correct | 107 ms | 120428 KB | Output is correct |
66 | Correct | 95 ms | 110572 KB | Output is correct |
67 | Correct | 92 ms | 105908 KB | Output is correct |
68 | Correct | 84 ms | 97772 KB | Output is correct |
69 | Correct | 107 ms | 119148 KB | Output is correct |
70 | Correct | 102 ms | 114308 KB | Output is correct |
71 | Correct | 102 ms | 115436 KB | Output is correct |
72 | Correct | 105 ms | 116844 KB | Output is correct |
73 | Correct | 97 ms | 108396 KB | Output is correct |
74 | Correct | 90 ms | 101228 KB | Output is correct |
75 | Correct | 96 ms | 111880 KB | Output is correct |
76 | Correct | 117 ms | 128108 KB | Output is correct |
77 | Correct | 115 ms | 128108 KB | Output is correct |
78 | Correct | 86 ms | 98924 KB | Output is correct |
79 | Correct | 87 ms | 102508 KB | Output is correct |
80 | Correct | 120 ms | 125548 KB | Output is correct |
81 | Correct | 87 ms | 103532 KB | Output is correct |
82 | Correct | 92 ms | 109420 KB | Output is correct |
83 | Correct | 119 ms | 133356 KB | Output is correct |
84 | Correct | 98 ms | 114284 KB | Output is correct |
85 | Correct | 107 ms | 124268 KB | Output is correct |
86 | Correct | 107 ms | 121836 KB | Output is correct |
87 | Correct | 96 ms | 111852 KB | Output is correct |
88 | Correct | 124 ms | 134636 KB | Output is correct |
89 | Correct | 122 ms | 134636 KB | Output is correct |
90 | Correct | 93 ms | 113132 KB | Output is correct |
91 | Correct | 123 ms | 134636 KB | Output is correct |
92 | Correct | 124 ms | 134636 KB | Output is correct |
93 | Correct | 117 ms | 131948 KB | Output is correct |