Submission #680913

# Submission time Handle Problem Language Result Execution time Memory
680913 2023-01-12T03:09:19 Z uylulu Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
270 ms 133344 KB
#include <bits/stdc++.h>
using namespace std;

#define double long double
#define int long long
#define endl "\n"

const int N = 200 + 3,oo = 1e17;

int dp[N + 1][N + 1][N + 1][2];

int x[N + 1],t[N + 1];

int n,len;

int f(int l,int r,int cnt,int side) {
    if(l == n + 1 && r == 0) {
        if(cnt != 0) {
            return oo;
        }
        return 0;
    }

    // cout<<cnt<<endl;

    if(dp[l][r][cnt][side] != -1) return dp[l][r][cnt][side];

    int res = oo;

    // cout<<l<<" "<<r<<" "<<cnt<<endl;

    if(side == 1) {
        if(r > 0) {
            res = min(res,f(l,r - 1,cnt,1) + (x[r] - x[r - 1]));
            res = min(res,f(l,r - 1,cnt,0) + (len - x[l]) + x[r]);
        }
    
        if(r > 0 && cnt > 0) {
            int tl = f(l,r - 1,cnt - 1,1);

            if(t[r] >= tl + (x[r] - x[r - 1])) {
                res = min(res,tl + x[r] - x[r - 1]);
            }

            tl = f(l,r - 1,cnt - 1,0);

            if(t[r] >= tl + (len - x[l]) + x[r]) {
                res = min(res,tl + (len - x[l]) + x[r]);
            }
        }
        return dp[l][r][cnt][side] = res;
    } else {
        if(l <= n) {
            res = min(res,f(l + 1,r,cnt,0) + abs(x[l] - x[l + 1]));
            res = min(res,f(l + 1,r,cnt,1) + (len - x[l]) + x[r]);
        }
        if(l <= n && cnt > 0) {
            int tl = f(l + 1,r,cnt - 1,0);

            if(t[l] >= tl + abs(x[l] - x[l + 1])) {
                res = min(res,tl + abs(x[l] - x[l + 1]));
            }
            tl = f(l + 1,r,cnt - 1,1);

            if(t[l] >= tl + (len - x[l]) + x[r]) {
                res = min(res,tl + (len - x[l]) + x[r]);
            }
        }
        return dp[l][r][cnt][side] = res;
    }
    return dp[l][r][cnt][side] = oo;
}

signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);

    memset(dp,-1,sizeof(dp));

    cin>>n>>len;

    for(int i = 1;i <= n;i++) {
        cin>>x[i];
    }
    for(int i = 1;i <= n;i++) {
        cin>>t[i];
    }
    int res = 0;

    if(x[n] == len) {
        res++;
        n--;
    }
    x[0] = 0;
    x[n + 1] = len;

    int sum = 0;

    // cout<<f(0,4,7,1)<<endl;

    for(int i = 0;i <= n;i++) {
        for(int j = i + 1;j <= n + 1;j++) {
            for(int k = 0;k <= n;k++) {
                int asd = min(f(j,i,k,0),f(j,i,k,1));

                if(asd < oo) {
                    sum = max(sum,k);
                    // cout<<j<<" "<<i<<" "<<k<<endl;
                }

            }
        }
    }
    cout<<res + sum<<endl;

    return 0;
}       
# Verdict Execution time Memory Grader output
1 Correct 52 ms 133160 KB Output is correct
2 Correct 55 ms 133204 KB Output is correct
3 Correct 58 ms 133136 KB Output is correct
4 Correct 54 ms 133120 KB Output is correct
5 Correct 55 ms 133116 KB Output is correct
6 Correct 55 ms 133204 KB Output is correct
7 Correct 61 ms 133148 KB Output is correct
8 Correct 58 ms 133132 KB Output is correct
9 Correct 55 ms 133104 KB Output is correct
10 Correct 55 ms 133116 KB Output is correct
11 Correct 56 ms 133112 KB Output is correct
12 Correct 54 ms 133172 KB Output is correct
13 Correct 73 ms 133152 KB Output is correct
14 Correct 52 ms 133172 KB Output is correct
15 Correct 53 ms 133196 KB Output is correct
16 Correct 51 ms 133116 KB Output is correct
17 Correct 51 ms 133196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 133160 KB Output is correct
2 Correct 55 ms 133204 KB Output is correct
3 Correct 58 ms 133136 KB Output is correct
4 Correct 54 ms 133120 KB Output is correct
5 Correct 55 ms 133116 KB Output is correct
6 Correct 55 ms 133204 KB Output is correct
7 Correct 61 ms 133148 KB Output is correct
8 Correct 58 ms 133132 KB Output is correct
9 Correct 55 ms 133104 KB Output is correct
10 Correct 55 ms 133116 KB Output is correct
11 Correct 56 ms 133112 KB Output is correct
12 Correct 54 ms 133172 KB Output is correct
13 Correct 73 ms 133152 KB Output is correct
14 Correct 52 ms 133172 KB Output is correct
15 Correct 53 ms 133196 KB Output is correct
16 Correct 51 ms 133116 KB Output is correct
17 Correct 51 ms 133196 KB Output is correct
18 Correct 52 ms 133172 KB Output is correct
19 Correct 57 ms 133196 KB Output is correct
20 Correct 50 ms 133184 KB Output is correct
21 Correct 51 ms 133292 KB Output is correct
22 Correct 51 ms 133208 KB Output is correct
23 Correct 60 ms 133108 KB Output is correct
24 Correct 54 ms 133196 KB Output is correct
25 Correct 54 ms 133196 KB Output is correct
26 Correct 52 ms 133184 KB Output is correct
27 Correct 52 ms 133160 KB Output is correct
28 Correct 54 ms 133096 KB Output is correct
29 Correct 53 ms 133192 KB Output is correct
30 Correct 53 ms 133176 KB Output is correct
31 Correct 52 ms 133192 KB Output is correct
32 Correct 51 ms 133104 KB Output is correct
33 Correct 51 ms 133152 KB Output is correct
34 Correct 51 ms 133196 KB Output is correct
35 Correct 50 ms 133208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 133160 KB Output is correct
2 Correct 55 ms 133204 KB Output is correct
3 Correct 58 ms 133136 KB Output is correct
4 Correct 54 ms 133120 KB Output is correct
5 Correct 55 ms 133116 KB Output is correct
6 Correct 55 ms 133204 KB Output is correct
7 Correct 61 ms 133148 KB Output is correct
8 Correct 58 ms 133132 KB Output is correct
9 Correct 55 ms 133104 KB Output is correct
10 Correct 55 ms 133116 KB Output is correct
11 Correct 56 ms 133112 KB Output is correct
12 Correct 54 ms 133172 KB Output is correct
13 Correct 73 ms 133152 KB Output is correct
14 Correct 52 ms 133172 KB Output is correct
15 Correct 53 ms 133196 KB Output is correct
16 Correct 51 ms 133116 KB Output is correct
17 Correct 51 ms 133196 KB Output is correct
18 Correct 187 ms 133228 KB Output is correct
19 Correct 120 ms 133220 KB Output is correct
20 Correct 77 ms 133196 KB Output is correct
21 Correct 136 ms 133220 KB Output is correct
22 Correct 142 ms 133196 KB Output is correct
23 Correct 71 ms 133208 KB Output is correct
24 Correct 65 ms 133216 KB Output is correct
25 Correct 70 ms 133196 KB Output is correct
26 Correct 54 ms 133096 KB Output is correct
27 Correct 70 ms 133100 KB Output is correct
28 Correct 62 ms 133152 KB Output is correct
29 Correct 71 ms 133176 KB Output is correct
30 Correct 66 ms 133100 KB Output is correct
31 Correct 70 ms 133212 KB Output is correct
32 Correct 75 ms 133144 KB Output is correct
33 Correct 71 ms 133256 KB Output is correct
34 Correct 54 ms 133200 KB Output is correct
35 Correct 70 ms 133180 KB Output is correct
36 Correct 55 ms 133216 KB Output is correct
37 Correct 76 ms 133204 KB Output is correct
38 Correct 58 ms 133096 KB Output is correct
39 Correct 72 ms 133252 KB Output is correct
40 Correct 62 ms 133196 KB Output is correct
41 Correct 244 ms 133344 KB Output is correct
42 Correct 150 ms 133228 KB Output is correct
43 Correct 240 ms 133228 KB Output is correct
44 Correct 150 ms 133156 KB Output is correct
45 Correct 244 ms 133220 KB Output is correct
46 Correct 153 ms 133224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 133160 KB Output is correct
2 Correct 55 ms 133204 KB Output is correct
3 Correct 58 ms 133136 KB Output is correct
4 Correct 54 ms 133120 KB Output is correct
5 Correct 55 ms 133116 KB Output is correct
6 Correct 55 ms 133204 KB Output is correct
7 Correct 61 ms 133148 KB Output is correct
8 Correct 58 ms 133132 KB Output is correct
9 Correct 55 ms 133104 KB Output is correct
10 Correct 55 ms 133116 KB Output is correct
11 Correct 56 ms 133112 KB Output is correct
12 Correct 54 ms 133172 KB Output is correct
13 Correct 73 ms 133152 KB Output is correct
14 Correct 52 ms 133172 KB Output is correct
15 Correct 53 ms 133196 KB Output is correct
16 Correct 51 ms 133116 KB Output is correct
17 Correct 51 ms 133196 KB Output is correct
18 Correct 52 ms 133172 KB Output is correct
19 Correct 57 ms 133196 KB Output is correct
20 Correct 50 ms 133184 KB Output is correct
21 Correct 51 ms 133292 KB Output is correct
22 Correct 51 ms 133208 KB Output is correct
23 Correct 60 ms 133108 KB Output is correct
24 Correct 54 ms 133196 KB Output is correct
25 Correct 54 ms 133196 KB Output is correct
26 Correct 52 ms 133184 KB Output is correct
27 Correct 52 ms 133160 KB Output is correct
28 Correct 54 ms 133096 KB Output is correct
29 Correct 53 ms 133192 KB Output is correct
30 Correct 53 ms 133176 KB Output is correct
31 Correct 52 ms 133192 KB Output is correct
32 Correct 51 ms 133104 KB Output is correct
33 Correct 51 ms 133152 KB Output is correct
34 Correct 51 ms 133196 KB Output is correct
35 Correct 50 ms 133208 KB Output is correct
36 Correct 187 ms 133228 KB Output is correct
37 Correct 120 ms 133220 KB Output is correct
38 Correct 77 ms 133196 KB Output is correct
39 Correct 136 ms 133220 KB Output is correct
40 Correct 142 ms 133196 KB Output is correct
41 Correct 71 ms 133208 KB Output is correct
42 Correct 65 ms 133216 KB Output is correct
43 Correct 70 ms 133196 KB Output is correct
44 Correct 54 ms 133096 KB Output is correct
45 Correct 70 ms 133100 KB Output is correct
46 Correct 62 ms 133152 KB Output is correct
47 Correct 71 ms 133176 KB Output is correct
48 Correct 66 ms 133100 KB Output is correct
49 Correct 70 ms 133212 KB Output is correct
50 Correct 75 ms 133144 KB Output is correct
51 Correct 71 ms 133256 KB Output is correct
52 Correct 54 ms 133200 KB Output is correct
53 Correct 70 ms 133180 KB Output is correct
54 Correct 55 ms 133216 KB Output is correct
55 Correct 76 ms 133204 KB Output is correct
56 Correct 58 ms 133096 KB Output is correct
57 Correct 72 ms 133252 KB Output is correct
58 Correct 62 ms 133196 KB Output is correct
59 Correct 244 ms 133344 KB Output is correct
60 Correct 150 ms 133228 KB Output is correct
61 Correct 240 ms 133228 KB Output is correct
62 Correct 150 ms 133156 KB Output is correct
63 Correct 244 ms 133220 KB Output is correct
64 Correct 153 ms 133224 KB Output is correct
65 Correct 215 ms 133296 KB Output is correct
66 Correct 194 ms 133292 KB Output is correct
67 Correct 182 ms 133224 KB Output is correct
68 Correct 175 ms 133224 KB Output is correct
69 Correct 219 ms 133228 KB Output is correct
70 Correct 194 ms 133232 KB Output is correct
71 Correct 220 ms 133228 KB Output is correct
72 Correct 201 ms 133224 KB Output is correct
73 Correct 187 ms 133180 KB Output is correct
74 Correct 173 ms 133224 KB Output is correct
75 Correct 193 ms 133196 KB Output is correct
76 Correct 232 ms 133232 KB Output is correct
77 Correct 224 ms 133324 KB Output is correct
78 Correct 172 ms 133324 KB Output is correct
79 Correct 194 ms 133268 KB Output is correct
80 Correct 222 ms 133132 KB Output is correct
81 Correct 182 ms 133324 KB Output is correct
82 Correct 188 ms 133232 KB Output is correct
83 Correct 232 ms 133196 KB Output is correct
84 Correct 207 ms 133232 KB Output is correct
85 Correct 219 ms 133232 KB Output is correct
86 Correct 206 ms 133240 KB Output is correct
87 Correct 193 ms 133324 KB Output is correct
88 Correct 240 ms 133320 KB Output is correct
89 Correct 237 ms 133228 KB Output is correct
90 Correct 219 ms 133144 KB Output is correct
91 Correct 253 ms 133244 KB Output is correct
92 Correct 237 ms 133236 KB Output is correct
93 Correct 270 ms 133232 KB Output is correct