Submission #462453

# Submission time Handle Problem Language Result Execution time Memory
462453 2021-08-10T14:49:40 Z JovanB Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
194 ms 129488 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
ll dp[205][205][2][205];
 
const ll INF = 1e15;
 
ll a[205];
ll b[205];
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;
 
    ll n, l;
    cin >> n >> l;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=n; i++){
        cin >> b[i];
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=0; k<=1; k++){
                for(int r=0; r<=n; r++){
                    dp[i][j][k][r] = INF;
                }
            }
        }
    }
    dp[1][1][1][(b[1] >= a[1])] = a[1];
    dp[n][n][0][(b[n] >= l-a[n])] = l-a[n];
    for(int len=1; len<n; len++){
        for(int i=n; i>=1; i--){
            int ost = len-(n-i+1);
            if(ost <= 0) break;
            int j = ost;
            for(int k=0; k<=n; k++){
                ll vreme = dp[i][j][0][k];
                int novi = (vreme+a[i]-a[i-1] <= b[i-1]) + k;
                dp[i-1][j][0][novi] = min(dp[i-1][j][0][novi], vreme+a[i]-a[i-1]);
                novi = (vreme+l-a[i]+a[j+1] <= b[j+1]) + k;
                dp[i][j+1][1][novi] = min(dp[i][j+1][1][novi], vreme+l-a[i]+a[j+1]);
                vreme = dp[i][j][1][k];
                novi = (vreme+a[j+1]-a[j] <= b[j+1]) + k;
                dp[i][j+1][1][novi] = min(dp[i][j+1][1][novi], vreme+a[j+1]-a[j]);
                novi = (vreme+l-a[i-1]+a[j] <= b[i-1]) + k;
                dp[i-1][j][0][novi] = min(dp[i-1][j][0][novi], vreme+l-a[i-1]+a[j]);
            }
        }
        for(int k=0; k<=n; k++){
            ll vreme = dp[1][len][1][k];
            int novi = (vreme+a[len+1]-a[len] <= b[len+1]) + k;
            dp[1][len+1][1][novi] = min(dp[1][len+1][1][novi], vreme+a[len+1]-a[len]);
            novi = (vreme+l-a[n]+a[len] <= b[n]) + k;
            dp[n][len][0][novi] = min(dp[n][len][0][novi], vreme+l-a[n]+a[len]);
            int j = n-len+1;
            vreme = dp[j][n][0][k];
            novi = (vreme+a[j]-a[j-1] <= b[j-1]) + k;
            dp[j-1][n][0][novi] = min(dp[j-1][n][0][novi], vreme+a[j]-a[j-1]);
            novi = (vreme+a[1]+l-a[j] <= b[1]) + k;
            dp[j][1][1][novi] = min(dp[j][1][1][novi], vreme+a[1]+l-a[j]);
        }
    }
    int res = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=0; k<=1; k++){
                for(int r=0; r<=n; r++){
                    if(dp[i][j][k][r] != INF) res = max(res, r);
                }
            }
        }
    }
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 832 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 832 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 1 ms 844 KB Output is correct
25 Correct 1 ms 1024 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 444 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 972 KB Output is correct
31 Correct 1 ms 972 KB Output is correct
32 Correct 1 ms 844 KB Output is correct
33 Correct 2 ms 1100 KB Output is correct
34 Correct 1 ms 972 KB Output is correct
35 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 832 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 127 ms 103844 KB Output is correct
19 Correct 66 ms 62832 KB Output is correct
20 Correct 34 ms 33452 KB Output is correct
21 Correct 62 ms 59324 KB Output is correct
22 Correct 84 ms 76904 KB Output is correct
23 Correct 27 ms 28336 KB Output is correct
24 Correct 20 ms 22216 KB Output is correct
25 Correct 25 ms 27748 KB Output is correct
26 Correct 8 ms 10488 KB Output is correct
27 Correct 26 ms 28980 KB Output is correct
28 Correct 19 ms 20556 KB Output is correct
29 Correct 26 ms 29644 KB Output is correct
30 Correct 23 ms 23244 KB Output is correct
31 Correct 24 ms 27824 KB Output is correct
32 Correct 13 ms 14548 KB Output is correct
33 Correct 25 ms 27732 KB Output is correct
34 Correct 9 ms 9804 KB Output is correct
35 Correct 27 ms 27196 KB Output is correct
36 Correct 11 ms 12872 KB Output is correct
37 Correct 28 ms 29032 KB Output is correct
38 Correct 16 ms 15820 KB Output is correct
39 Correct 29 ms 30260 KB Output is correct
40 Correct 14 ms 17612 KB Output is correct
41 Correct 160 ms 128164 KB Output is correct
42 Correct 95 ms 86224 KB Output is correct
43 Correct 172 ms 128200 KB Output is correct
44 Correct 100 ms 85128 KB Output is correct
45 Correct 152 ms 128208 KB Output is correct
46 Correct 92 ms 86220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 832 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 1 ms 844 KB Output is correct
25 Correct 1 ms 1024 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 444 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 972 KB Output is correct
31 Correct 1 ms 972 KB Output is correct
32 Correct 1 ms 844 KB Output is correct
33 Correct 2 ms 1100 KB Output is correct
34 Correct 1 ms 972 KB Output is correct
35 Correct 1 ms 1100 KB Output is correct
36 Correct 127 ms 103844 KB Output is correct
37 Correct 66 ms 62832 KB Output is correct
38 Correct 34 ms 33452 KB Output is correct
39 Correct 62 ms 59324 KB Output is correct
40 Correct 84 ms 76904 KB Output is correct
41 Correct 27 ms 28336 KB Output is correct
42 Correct 20 ms 22216 KB Output is correct
43 Correct 25 ms 27748 KB Output is correct
44 Correct 8 ms 10488 KB Output is correct
45 Correct 26 ms 28980 KB Output is correct
46 Correct 19 ms 20556 KB Output is correct
47 Correct 26 ms 29644 KB Output is correct
48 Correct 23 ms 23244 KB Output is correct
49 Correct 24 ms 27824 KB Output is correct
50 Correct 13 ms 14548 KB Output is correct
51 Correct 25 ms 27732 KB Output is correct
52 Correct 9 ms 9804 KB Output is correct
53 Correct 27 ms 27196 KB Output is correct
54 Correct 11 ms 12872 KB Output is correct
55 Correct 28 ms 29032 KB Output is correct
56 Correct 16 ms 15820 KB Output is correct
57 Correct 29 ms 30260 KB Output is correct
58 Correct 14 ms 17612 KB Output is correct
59 Correct 160 ms 128164 KB Output is correct
60 Correct 95 ms 86224 KB Output is correct
61 Correct 172 ms 128200 KB Output is correct
62 Correct 100 ms 85128 KB Output is correct
63 Correct 152 ms 128208 KB Output is correct
64 Correct 92 ms 86220 KB Output is correct
65 Correct 133 ms 115580 KB Output is correct
66 Correct 132 ms 106176 KB Output is correct
67 Correct 113 ms 101504 KB Output is correct
68 Correct 121 ms 93736 KB Output is correct
69 Correct 140 ms 114488 KB Output is correct
70 Correct 122 ms 109696 KB Output is correct
71 Correct 121 ms 110888 KB Output is correct
72 Correct 131 ms 112084 KB Output is correct
73 Correct 113 ms 103764 KB Output is correct
74 Correct 109 ms 97048 KB Output is correct
75 Correct 115 ms 107256 KB Output is correct
76 Correct 143 ms 123128 KB Output is correct
77 Correct 137 ms 123060 KB Output is correct
78 Correct 194 ms 94840 KB Output is correct
79 Correct 116 ms 98164 KB Output is correct
80 Correct 131 ms 120624 KB Output is correct
81 Correct 120 ms 99248 KB Output is correct
82 Correct 113 ms 104924 KB Output is correct
83 Correct 146 ms 128104 KB Output is correct
84 Correct 131 ms 109632 KB Output is correct
85 Correct 132 ms 119368 KB Output is correct
86 Correct 128 ms 116928 KB Output is correct
87 Correct 149 ms 107328 KB Output is correct
88 Correct 149 ms 129436 KB Output is correct
89 Correct 147 ms 129488 KB Output is correct
90 Correct 124 ms 108512 KB Output is correct
91 Correct 183 ms 129488 KB Output is correct
92 Correct 162 ms 129432 KB Output is correct
93 Correct 156 ms 126916 KB Output is correct