Submission #255147

# Submission time Handle Problem Language Result Execution time Memory
255147 2020-07-31T11:41:39 Z AM1648 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
136 ms 145528 KB
/* be name khoda */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define fori(i, n) forifrom(i, 0, n)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define forir(i, n) forirto(i, n, 0)

#define smin(a, b) a = min(a, b)

// ------------------------------------------------------------------

const ll INF = 4340410370284600380LL;
const ll maxn = 210;

ll N, L, X[maxn], T[maxn], dp[maxn][maxn][maxn][2];
// dp[k][l][r][2] -> minimum time to get k stamps

void update(ll k, ll l, ll r, ll b, ll a) {
    smin(dp[k][l][r][b], a);
    if (b == 0 && T[l] >= a || b == 1 && T[r] >= a) smin(dp[k + 1][l][r][b], a);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    //ifstream cin("3.in");

    cin >> N >> L;
    fori (i, N) cin >> X[i + 1];
    fori (i, N) cin >> T[i + 1];
    X[N + 1] = L;

    memset(dp, 60, sizeof dp);
    ll ans = 0; 
    dp[0][0][N + 1][0] = dp[0][0][N + 1][1] = 0;
    fori (k, N + 1) {
        forirto (t, N + 2, 1) {
            fori (l, N - t + 2) {
                ll r = l + t;
                ll vl = dp[k][l][r][0], vr = dp[k][l][r][1];
                if (vl < INF) {
                    ans = k;
                    update(k, l + 1, r, 0, vl + X[l + 1] - X[l]);
                    update(k, l, r - 1, 1, vl + X[l] + L - X[r - 1]);
                }
                if (vr < INF) {
                    ans = k;
                    update(k, l, r - 1, 1, vr + X[r] - X[r - 1]);
                    update(k, l + 1, r, 0, vr + L - X[r] + X[l + 1]);
                }
            }
        }
    }
    cout << ans << '\n';

}

Compilation message

ho_t3.cpp: In function 'void update(ll, ll, ll, ll, ll)':
ho_t3.cpp:24:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (b == 0 && T[l] >= a || b == 1 && T[r] >= a) smin(dp[k + 1][l][r][b], a);
         ~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 73 ms 145276 KB Output is correct
2 Correct 78 ms 145400 KB Output is correct
3 Correct 73 ms 145344 KB Output is correct
4 Correct 71 ms 145272 KB Output is correct
5 Correct 71 ms 145272 KB Output is correct
6 Correct 72 ms 145400 KB Output is correct
7 Correct 73 ms 145272 KB Output is correct
8 Correct 72 ms 145368 KB Output is correct
9 Correct 71 ms 145272 KB Output is correct
10 Correct 73 ms 145272 KB Output is correct
11 Correct 72 ms 145272 KB Output is correct
12 Correct 72 ms 145400 KB Output is correct
13 Correct 72 ms 145272 KB Output is correct
14 Correct 72 ms 145272 KB Output is correct
15 Correct 76 ms 145312 KB Output is correct
16 Correct 79 ms 145272 KB Output is correct
17 Correct 73 ms 145400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 145276 KB Output is correct
2 Correct 78 ms 145400 KB Output is correct
3 Correct 73 ms 145344 KB Output is correct
4 Correct 71 ms 145272 KB Output is correct
5 Correct 71 ms 145272 KB Output is correct
6 Correct 72 ms 145400 KB Output is correct
7 Correct 73 ms 145272 KB Output is correct
8 Correct 72 ms 145368 KB Output is correct
9 Correct 71 ms 145272 KB Output is correct
10 Correct 73 ms 145272 KB Output is correct
11 Correct 72 ms 145272 KB Output is correct
12 Correct 72 ms 145400 KB Output is correct
13 Correct 72 ms 145272 KB Output is correct
14 Correct 72 ms 145272 KB Output is correct
15 Correct 76 ms 145312 KB Output is correct
16 Correct 79 ms 145272 KB Output is correct
17 Correct 73 ms 145400 KB Output is correct
18 Correct 70 ms 145320 KB Output is correct
19 Correct 70 ms 145320 KB Output is correct
20 Correct 71 ms 145272 KB Output is correct
21 Correct 71 ms 145272 KB Output is correct
22 Correct 79 ms 145272 KB Output is correct
23 Correct 71 ms 145272 KB Output is correct
24 Correct 70 ms 145284 KB Output is correct
25 Correct 74 ms 145272 KB Output is correct
26 Correct 69 ms 145260 KB Output is correct
27 Correct 71 ms 145276 KB Output is correct
28 Correct 72 ms 145260 KB Output is correct
29 Correct 75 ms 145276 KB Output is correct
30 Correct 71 ms 145272 KB Output is correct
31 Correct 72 ms 145288 KB Output is correct
32 Correct 72 ms 145272 KB Output is correct
33 Correct 75 ms 145272 KB Output is correct
34 Correct 76 ms 145276 KB Output is correct
35 Correct 70 ms 145288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 145276 KB Output is correct
2 Correct 78 ms 145400 KB Output is correct
3 Correct 73 ms 145344 KB Output is correct
4 Correct 71 ms 145272 KB Output is correct
5 Correct 71 ms 145272 KB Output is correct
6 Correct 72 ms 145400 KB Output is correct
7 Correct 73 ms 145272 KB Output is correct
8 Correct 72 ms 145368 KB Output is correct
9 Correct 71 ms 145272 KB Output is correct
10 Correct 73 ms 145272 KB Output is correct
11 Correct 72 ms 145272 KB Output is correct
12 Correct 72 ms 145400 KB Output is correct
13 Correct 72 ms 145272 KB Output is correct
14 Correct 72 ms 145272 KB Output is correct
15 Correct 76 ms 145312 KB Output is correct
16 Correct 79 ms 145272 KB Output is correct
17 Correct 73 ms 145400 KB Output is correct
18 Correct 109 ms 145272 KB Output is correct
19 Correct 101 ms 145272 KB Output is correct
20 Correct 85 ms 145272 KB Output is correct
21 Correct 89 ms 145272 KB Output is correct
22 Correct 96 ms 145272 KB Output is correct
23 Correct 79 ms 145272 KB Output is correct
24 Correct 71 ms 145276 KB Output is correct
25 Correct 77 ms 145272 KB Output is correct
26 Correct 73 ms 145272 KB Output is correct
27 Correct 80 ms 145272 KB Output is correct
28 Correct 73 ms 145272 KB Output is correct
29 Correct 78 ms 145272 KB Output is correct
30 Correct 72 ms 145272 KB Output is correct
31 Correct 78 ms 145272 KB Output is correct
32 Correct 72 ms 145272 KB Output is correct
33 Correct 75 ms 145272 KB Output is correct
34 Correct 72 ms 145272 KB Output is correct
35 Correct 74 ms 145296 KB Output is correct
36 Correct 73 ms 145272 KB Output is correct
37 Correct 75 ms 145272 KB Output is correct
38 Correct 72 ms 145272 KB Output is correct
39 Correct 78 ms 145272 KB Output is correct
40 Correct 77 ms 145380 KB Output is correct
41 Correct 128 ms 145368 KB Output is correct
42 Correct 89 ms 145272 KB Output is correct
43 Correct 132 ms 145308 KB Output is correct
44 Correct 87 ms 145272 KB Output is correct
45 Correct 123 ms 145272 KB Output is correct
46 Correct 87 ms 145272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 145276 KB Output is correct
2 Correct 78 ms 145400 KB Output is correct
3 Correct 73 ms 145344 KB Output is correct
4 Correct 71 ms 145272 KB Output is correct
5 Correct 71 ms 145272 KB Output is correct
6 Correct 72 ms 145400 KB Output is correct
7 Correct 73 ms 145272 KB Output is correct
8 Correct 72 ms 145368 KB Output is correct
9 Correct 71 ms 145272 KB Output is correct
10 Correct 73 ms 145272 KB Output is correct
11 Correct 72 ms 145272 KB Output is correct
12 Correct 72 ms 145400 KB Output is correct
13 Correct 72 ms 145272 KB Output is correct
14 Correct 72 ms 145272 KB Output is correct
15 Correct 76 ms 145312 KB Output is correct
16 Correct 79 ms 145272 KB Output is correct
17 Correct 73 ms 145400 KB Output is correct
18 Correct 70 ms 145320 KB Output is correct
19 Correct 70 ms 145320 KB Output is correct
20 Correct 71 ms 145272 KB Output is correct
21 Correct 71 ms 145272 KB Output is correct
22 Correct 79 ms 145272 KB Output is correct
23 Correct 71 ms 145272 KB Output is correct
24 Correct 70 ms 145284 KB Output is correct
25 Correct 74 ms 145272 KB Output is correct
26 Correct 69 ms 145260 KB Output is correct
27 Correct 71 ms 145276 KB Output is correct
28 Correct 72 ms 145260 KB Output is correct
29 Correct 75 ms 145276 KB Output is correct
30 Correct 71 ms 145272 KB Output is correct
31 Correct 72 ms 145288 KB Output is correct
32 Correct 72 ms 145272 KB Output is correct
33 Correct 75 ms 145272 KB Output is correct
34 Correct 76 ms 145276 KB Output is correct
35 Correct 70 ms 145288 KB Output is correct
36 Correct 109 ms 145272 KB Output is correct
37 Correct 101 ms 145272 KB Output is correct
38 Correct 85 ms 145272 KB Output is correct
39 Correct 89 ms 145272 KB Output is correct
40 Correct 96 ms 145272 KB Output is correct
41 Correct 79 ms 145272 KB Output is correct
42 Correct 71 ms 145276 KB Output is correct
43 Correct 77 ms 145272 KB Output is correct
44 Correct 73 ms 145272 KB Output is correct
45 Correct 80 ms 145272 KB Output is correct
46 Correct 73 ms 145272 KB Output is correct
47 Correct 78 ms 145272 KB Output is correct
48 Correct 72 ms 145272 KB Output is correct
49 Correct 78 ms 145272 KB Output is correct
50 Correct 72 ms 145272 KB Output is correct
51 Correct 75 ms 145272 KB Output is correct
52 Correct 72 ms 145272 KB Output is correct
53 Correct 74 ms 145296 KB Output is correct
54 Correct 73 ms 145272 KB Output is correct
55 Correct 75 ms 145272 KB Output is correct
56 Correct 72 ms 145272 KB Output is correct
57 Correct 78 ms 145272 KB Output is correct
58 Correct 77 ms 145380 KB Output is correct
59 Correct 128 ms 145368 KB Output is correct
60 Correct 89 ms 145272 KB Output is correct
61 Correct 132 ms 145308 KB Output is correct
62 Correct 87 ms 145272 KB Output is correct
63 Correct 123 ms 145272 KB Output is correct
64 Correct 87 ms 145272 KB Output is correct
65 Correct 110 ms 145272 KB Output is correct
66 Correct 107 ms 145272 KB Output is correct
67 Correct 114 ms 145416 KB Output is correct
68 Correct 99 ms 145400 KB Output is correct
69 Correct 116 ms 145356 KB Output is correct
70 Correct 123 ms 145272 KB Output is correct
71 Correct 113 ms 145268 KB Output is correct
72 Correct 127 ms 145272 KB Output is correct
73 Correct 112 ms 145272 KB Output is correct
74 Correct 121 ms 145304 KB Output is correct
75 Correct 115 ms 145272 KB Output is correct
76 Correct 132 ms 145400 KB Output is correct
77 Correct 118 ms 145272 KB Output is correct
78 Correct 108 ms 145272 KB Output is correct
79 Correct 108 ms 145400 KB Output is correct
80 Correct 120 ms 145272 KB Output is correct
81 Correct 106 ms 145272 KB Output is correct
82 Correct 103 ms 145272 KB Output is correct
83 Correct 121 ms 145528 KB Output is correct
84 Correct 107 ms 145400 KB Output is correct
85 Correct 107 ms 145272 KB Output is correct
86 Correct 112 ms 145272 KB Output is correct
87 Correct 110 ms 145272 KB Output is correct
88 Correct 136 ms 145380 KB Output is correct
89 Correct 133 ms 145272 KB Output is correct
90 Correct 95 ms 145276 KB Output is correct
91 Correct 133 ms 145272 KB Output is correct
92 Correct 134 ms 145272 KB Output is correct
93 Correct 104 ms 145272 KB Output is correct