Submission #373173

# Submission time Handle Problem Language Result Execution time Memory
373173 2021-03-03T15:41:50 Z Leonardo_Paes Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
195 ms 134124 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e2+10;
typedef long long ll;
const ll inf = 1e18;
ll dp[maxn][maxn][maxn][2], x[maxn], t[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n, l;
    cin >> n >> l;
    for(int i=1; i<=n; i++) cin >> x[i];
    for(int i=1; i<=n; i++) cin >> t[i];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<=n; k++){
                dp[i][j][k][0] = dp[i][j][k][1] = inf;
            }
        }
    }
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    auto prv = [&](ll x){
        if(x-1 < 1) return n;
        return x-1;
    };
    auto nxt = [&](ll x){
        if(x+1 > n) return 1LL;
        return x+1;
    };
    auto d = [&](ll a, ll b){
        if(a > b) swap(a, b);
        return min(x[b] - x[a], l - x[b] + x[a]);
    };
    auto min_self = [&](ll &a, ll &b){
        a = min(a, b);
    };
    for(ll len=0; len<n; len++){
        for(ll i=0; i<=n; i++){
            for(ll k=0; k<=len; k++){
                ll j = (i + len)%(n+1);
                //l -> l
                ll tt = dp[i][j][k][0] + d(prv(i), i);
                min_self(dp[prv(i)][j][k+(tt <= t[prv(i)])][0], tt);
                //r -> l
                tt = dp[i][j][k][1] + d(prv(i), j);
                min_self(dp[prv(i)][j][k+(tt <= t[prv(i)])][0], tt);
                //l -> r
                tt = dp[i][j][k][0] + d(i, nxt(j));
                min_self(dp[i][nxt(j)][k+(tt <= t[nxt(j)])][1], tt);
                //r -> r
                tt = dp[i][j][k][1] + d(j, nxt(j));
                min_self(dp[i][nxt(j)][k+(tt <= t[nxt(j)])][1], tt);
            }
        }
    }
    ll ans = 0;
    for(ll i=0; i<=n; i++){
        for(ll j=0; j<=n; j++){
            for(ll k=0; k<=n; k++){
                for(int q : {0, 1}){
                    if(dp[i][j][k][q] != inf) ans = max(ans, k);
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 768 KB Output is correct
23 Correct 1 ms 1260 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 1 ms 1260 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 1 ms 1260 KB Output is correct
34 Correct 1 ms 1260 KB Output is correct
35 Correct 1 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 137 ms 107572 KB Output is correct
19 Correct 74 ms 65184 KB Output is correct
20 Correct 36 ms 34864 KB Output is correct
21 Correct 75 ms 61652 KB Output is correct
22 Correct 93 ms 79980 KB Output is correct
23 Correct 30 ms 29676 KB Output is correct
24 Correct 22 ms 23276 KB Output is correct
25 Correct 28 ms 29036 KB Output is correct
26 Correct 12 ms 11116 KB Output is correct
27 Correct 29 ms 30316 KB Output is correct
28 Correct 21 ms 21660 KB Output is correct
29 Correct 30 ms 30956 KB Output is correct
30 Correct 23 ms 24300 KB Output is correct
31 Correct 28 ms 29036 KB Output is correct
32 Correct 13 ms 15212 KB Output is correct
33 Correct 28 ms 29036 KB Output is correct
34 Correct 8 ms 10496 KB Output is correct
35 Correct 27 ms 28396 KB Output is correct
36 Correct 11 ms 13548 KB Output is correct
37 Correct 29 ms 30316 KB Output is correct
38 Correct 16 ms 16620 KB Output is correct
39 Correct 33 ms 31596 KB Output is correct
40 Correct 16 ms 18540 KB Output is correct
41 Correct 171 ms 132716 KB Output is correct
42 Correct 106 ms 89324 KB Output is correct
43 Correct 181 ms 132716 KB Output is correct
44 Correct 106 ms 88300 KB Output is correct
45 Correct 171 ms 132716 KB Output is correct
46 Correct 121 ms 89324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 768 KB Output is correct
23 Correct 1 ms 1260 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 1 ms 1260 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 1 ms 1260 KB Output is correct
34 Correct 1 ms 1260 KB Output is correct
35 Correct 1 ms 1260 KB Output is correct
36 Correct 137 ms 107572 KB Output is correct
37 Correct 74 ms 65184 KB Output is correct
38 Correct 36 ms 34864 KB Output is correct
39 Correct 75 ms 61652 KB Output is correct
40 Correct 93 ms 79980 KB Output is correct
41 Correct 30 ms 29676 KB Output is correct
42 Correct 22 ms 23276 KB Output is correct
43 Correct 28 ms 29036 KB Output is correct
44 Correct 12 ms 11116 KB Output is correct
45 Correct 29 ms 30316 KB Output is correct
46 Correct 21 ms 21660 KB Output is correct
47 Correct 30 ms 30956 KB Output is correct
48 Correct 23 ms 24300 KB Output is correct
49 Correct 28 ms 29036 KB Output is correct
50 Correct 13 ms 15212 KB Output is correct
51 Correct 28 ms 29036 KB Output is correct
52 Correct 8 ms 10496 KB Output is correct
53 Correct 27 ms 28396 KB Output is correct
54 Correct 11 ms 13548 KB Output is correct
55 Correct 29 ms 30316 KB Output is correct
56 Correct 16 ms 16620 KB Output is correct
57 Correct 33 ms 31596 KB Output is correct
58 Correct 16 ms 18540 KB Output is correct
59 Correct 171 ms 132716 KB Output is correct
60 Correct 106 ms 89324 KB Output is correct
61 Correct 181 ms 132716 KB Output is correct
62 Correct 106 ms 88300 KB Output is correct
63 Correct 171 ms 132716 KB Output is correct
64 Correct 121 ms 89324 KB Output is correct
65 Correct 178 ms 119800 KB Output is correct
66 Correct 157 ms 110068 KB Output is correct
67 Correct 137 ms 105196 KB Output is correct
68 Correct 124 ms 97132 KB Output is correct
69 Correct 161 ms 118636 KB Output is correct
70 Correct 165 ms 113516 KB Output is correct
71 Correct 150 ms 114796 KB Output is correct
72 Correct 150 ms 115948 KB Output is correct
73 Correct 139 ms 107500 KB Output is correct
74 Correct 125 ms 100588 KB Output is correct
75 Correct 154 ms 111232 KB Output is correct
76 Correct 174 ms 127468 KB Output is correct
77 Correct 176 ms 127468 KB Output is correct
78 Correct 128 ms 98224 KB Output is correct
79 Correct 131 ms 101604 KB Output is correct
80 Correct 164 ms 124908 KB Output is correct
81 Correct 134 ms 102884 KB Output is correct
82 Correct 164 ms 108908 KB Output is correct
83 Correct 173 ms 132716 KB Output is correct
84 Correct 148 ms 113664 KB Output is correct
85 Correct 161 ms 123500 KB Output is correct
86 Correct 186 ms 121068 KB Output is correct
87 Correct 147 ms 111184 KB Output is correct
88 Correct 195 ms 134124 KB Output is correct
89 Correct 182 ms 133996 KB Output is correct
90 Correct 146 ms 112492 KB Output is correct
91 Correct 195 ms 134124 KB Output is correct
92 Correct 178 ms 133996 KB Output is correct
93 Correct 173 ms 131436 KB Output is correct