Submission #702574

# Submission time Handle Problem Language Result Execution time Memory
702574 2023-02-24T13:07:24 Z guagua0407 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
132 ms 129492 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define all(x) x.begin(),x.end()

const int mxn=205;
ll dp[mxn][mxn][mxn][2];
ll X[mxn];
ll T[mxn];
int n;
ll L;

ll dist(int a,int b){
    if(a<=b) return X[b]-X[a];
    return X[b]+L-X[a];
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>L;
    for(int i=0;i<n;i++){
        cin>>X[i];
    }
    for(int i=0;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++){
                for(int l=0;l<2;l++){
                    dp[i][j][k][l]=(ll)1e18;
                }
            }
        }
    }
    if(X[0]<=T[0]) dp[0][0][1][0]=dp[0][0][1][1]=X[0];
    else dp[0][0][0][0]=dp[0][0][0][1]=X[0];
    if(L-X[n-1]<=T[n-1]) dp[n-1][n-1][1][0]=dp[n-1][n-1][1][1]=L-X[n-1];
    else dp[n-1][n-1][0][0]=dp[n-1][n-1][0][1]=L-X[n-1];
    for(int gap=1;gap<n;gap++){
        for(int i=0;i<n;i++){
            int j=(i+gap)%n;
            dp[i][j][0][0]=min(dp[i][j][0][0],dp[(i+1)%n][j][0][0]+dist(i,(i+1)%n));
            dp[i][j][0][1]=min(dp[i][j][0][1],dp[i][(j-1+n)%n][0][1]+dist((j-1+n)%n,j));
            for(int k=1;k<=n;k++){
                if(dp[(i+1)%n][j][k-1][0]+dist(i,(i+1)%n)<=T[i]){
                    dp[i][j][k][0]=min(dp[i][j][k][0],dp[(i+1)%n][j][k-1][0]+dist(i,(i+1)%n));
                }
                else{
                    dp[i][j][k][0]=min(dp[i][j][k][0],dp[(i+1)%n][j][k][0]+dist(i,(i+1)%n));
                }
                if(dp[i][(j-1+n)%n][k-1][1]+dist((j-1+n)%n,j)<=T[j]){
                    dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][(j-1+n)%n][k-1][1]+dist((j-1+n)%n,j));
                }
                else{
                    dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][(j-1+n)%n][k][1]+dist((j-1+n)%n,j));
                }
            }
            for(int k=0;k<=n;k++){
                dp[i][j][k][0]=min(dp[i][j][k][0],dp[i][j][k][1]+dist(i,j));
                dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j][k][0]+dist(i,j));
            }
        }
    }
    for(int k=n;k>=0;k--){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int l=0;l<2;l++){
                    if(dp[i][j][k][l]<(ll)1e18){
                        cout<<k;
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 580 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 968 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 840 KB Output is correct
25 Correct 1 ms 968 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 968 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 1 ms 980 KB Output is correct
35 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 100 ms 103812 KB Output is correct
19 Correct 45 ms 62796 KB Output is correct
20 Correct 22 ms 33376 KB Output is correct
21 Correct 45 ms 59260 KB Output is correct
22 Correct 64 ms 76968 KB Output is correct
23 Correct 20 ms 28236 KB Output is correct
24 Correct 15 ms 22100 KB Output is correct
25 Correct 22 ms 27732 KB Output is correct
26 Correct 7 ms 10436 KB Output is correct
27 Correct 22 ms 28868 KB Output is correct
28 Correct 17 ms 20564 KB Output is correct
29 Correct 21 ms 29572 KB Output is correct
30 Correct 15 ms 23124 KB Output is correct
31 Correct 19 ms 27732 KB Output is correct
32 Correct 10 ms 14360 KB Output is correct
33 Correct 20 ms 27764 KB Output is correct
34 Correct 6 ms 9804 KB Output is correct
35 Correct 21 ms 27172 KB Output is correct
36 Correct 8 ms 12756 KB Output is correct
37 Correct 21 ms 28932 KB Output is correct
38 Correct 16 ms 15704 KB Output is correct
39 Correct 26 ms 30188 KB Output is correct
40 Correct 12 ms 17620 KB Output is correct
41 Correct 97 ms 128312 KB Output is correct
42 Correct 79 ms 86176 KB Output is correct
43 Correct 98 ms 128080 KB Output is correct
44 Correct 75 ms 85120 KB Output is correct
45 Correct 91 ms 128180 KB Output is correct
46 Correct 81 ms 86172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 580 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 968 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 840 KB Output is correct
25 Correct 1 ms 968 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 968 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 1 ms 980 KB Output is correct
35 Correct 1 ms 980 KB Output is correct
36 Correct 100 ms 103812 KB Output is correct
37 Correct 45 ms 62796 KB Output is correct
38 Correct 22 ms 33376 KB Output is correct
39 Correct 45 ms 59260 KB Output is correct
40 Correct 64 ms 76968 KB Output is correct
41 Correct 20 ms 28236 KB Output is correct
42 Correct 15 ms 22100 KB Output is correct
43 Correct 22 ms 27732 KB Output is correct
44 Correct 7 ms 10436 KB Output is correct
45 Correct 22 ms 28868 KB Output is correct
46 Correct 17 ms 20564 KB Output is correct
47 Correct 21 ms 29572 KB Output is correct
48 Correct 15 ms 23124 KB Output is correct
49 Correct 19 ms 27732 KB Output is correct
50 Correct 10 ms 14360 KB Output is correct
51 Correct 20 ms 27764 KB Output is correct
52 Correct 6 ms 9804 KB Output is correct
53 Correct 21 ms 27172 KB Output is correct
54 Correct 8 ms 12756 KB Output is correct
55 Correct 21 ms 28932 KB Output is correct
56 Correct 16 ms 15704 KB Output is correct
57 Correct 26 ms 30188 KB Output is correct
58 Correct 12 ms 17620 KB Output is correct
59 Correct 97 ms 128312 KB Output is correct
60 Correct 79 ms 86176 KB Output is correct
61 Correct 98 ms 128080 KB Output is correct
62 Correct 75 ms 85120 KB Output is correct
63 Correct 91 ms 128180 KB Output is correct
64 Correct 81 ms 86172 KB Output is correct
65 Correct 100 ms 115604 KB Output is correct
66 Correct 84 ms 106140 KB Output is correct
67 Correct 79 ms 101404 KB Output is correct
68 Correct 73 ms 93684 KB Output is correct
69 Correct 93 ms 114388 KB Output is correct
70 Correct 81 ms 109656 KB Output is correct
71 Correct 87 ms 110856 KB Output is correct
72 Correct 77 ms 111988 KB Output is correct
73 Correct 82 ms 103756 KB Output is correct
74 Correct 62 ms 97008 KB Output is correct
75 Correct 99 ms 107308 KB Output is correct
76 Correct 86 ms 123032 KB Output is correct
77 Correct 114 ms 123112 KB Output is correct
78 Correct 68 ms 94796 KB Output is correct
79 Correct 77 ms 98132 KB Output is correct
80 Correct 93 ms 120616 KB Output is correct
81 Correct 78 ms 99148 KB Output is correct
82 Correct 89 ms 104872 KB Output is correct
83 Correct 114 ms 128200 KB Output is correct
84 Correct 92 ms 109624 KB Output is correct
85 Correct 107 ms 119352 KB Output is correct
86 Correct 99 ms 116908 KB Output is correct
87 Correct 83 ms 107308 KB Output is correct
88 Correct 89 ms 129448 KB Output is correct
89 Correct 113 ms 129444 KB Output is correct
90 Correct 115 ms 108488 KB Output is correct
91 Correct 88 ms 129484 KB Output is correct
92 Correct 95 ms 129492 KB Output is correct
93 Correct 132 ms 126920 KB Output is correct