Submission #702608

# Submission time Handle Problem Language Result Execution time Memory
702608 2023-02-24T14:54:36 Z 1075508020060209tc Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
180 ms 298340 KB
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second

int n;int L;
int xar[2010];
int tar[2010];
int dpl[300][300][300];
int dpr[300][300][300];
signed main(){

    cin>>n>>L;
    for(int i=1;i<=n;i++){
        cin>>xar[i];
    }xar[n+1]=L;
    for(int i=1;i<=n;i++){
        cin>>tar[i];
    }
    for(int i=0;i<=250;i++){
        for(int j=0;j<=250;j++){
            for(int k=0;k<=250;k++){
                dpl[i][j][k]=1e16;
                dpr[i][j][k]=1e16;
            }
        }
    }

    dpl[0][0][0]=0;
    dpr[0][0][0]=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                if(i+j>=n){continue;}
                if(dpr[i][j][k]<1e16){
                if(tar[j+1]>=dpr[i][j][k]+xar[j+1]-xar[j]){
                    dpr[i][j+1][k+1]=min(dpr[i][j+1][k+1],dpr[i][j][k]+xar[j+1]-xar[j]);
                }else{
                    dpr[i][j+1][k]=min(dpr[i][j+1][k],dpr[i][j][k]+xar[j+1]-xar[j]);
                }

                if(tar[n-(i+1)+1]>=dpr[i][j][k]+xar[j]+L-xar[n-(i+1)+1]){
                    dpl[i+1][j][k+1]=min(dpl[i+1][j][k+1],dpr[i][j][k]+xar[j]+L-xar[n-(i+1)+1]);
                }else{
                    dpl[i+1][j][k]=min(dpl[i+1][j][k],dpr[i][j][k]+xar[j]+L-xar[n-(i+1)+1]);
                }
                }
                if(dpl[i][j][k]<1e16){
                if(tar[j+1]>=dpl[i][j][k]+L-xar[n-i+1]+xar[j+1]){
                    dpr[i][j+1][k+1]=min(dpr[i][j+1][k+1],dpl[i][j][k]+L-xar[n-i+1]+xar[j+1]);
                }else{
                    dpr[i][j+1][k]=min(dpr[i][j+1][k],dpl[i][j][k]+L-xar[n-i+1]+xar[j+1]);
                }

                if(tar[n-(i+1)+1]>=dpl[i][j][k]+xar[n-i+1]-xar[n-(i+1)+1]){
                    dpl[i+1][j][k+1]=min(dpl[i+1][j][k+1],dpl[i][j][k]+xar[n-i+1]-xar[n-(i+1)+1]);
                }else{
                    dpl[i+1][j][k]=min(dpl[i+1][j][k],dpl[i][j][k]+xar[n-i+1]-xar[n-(i+1)+1]);
                }
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<=n;i++){
        for(int k=0;k<=n;k++){
            if(dpl[i][n-i][k]<1e16){
                ans=max(ans,k);
            }
            if(dpr[i][n-i][k]<1e16){
                ans=max(ans,k);
            }
            //cout<<i<<" "<<k<<" "<<dpl[i][n-i][k]<<"\n";
        }
    }


    cout<<ans<<endl;

    int a;int b;int c;int d;
    while(cin>>a){
        cin>>b>>c>>d;
        if(a==0){
            cout<<dpl[b][c][d]<<endl;
        }else{
            cout<<dpr[b][c][d]<<endl;
        }
    }

}
# Verdict Execution time Memory Grader output
1 Correct 133 ms 298060 KB Output is correct
2 Correct 125 ms 298088 KB Output is correct
3 Correct 131 ms 298060 KB Output is correct
4 Correct 134 ms 298060 KB Output is correct
5 Correct 120 ms 298092 KB Output is correct
6 Correct 119 ms 298076 KB Output is correct
7 Correct 116 ms 298032 KB Output is correct
8 Correct 122 ms 298064 KB Output is correct
9 Correct 130 ms 298112 KB Output is correct
10 Correct 131 ms 298072 KB Output is correct
11 Correct 134 ms 298108 KB Output is correct
12 Correct 125 ms 298008 KB Output is correct
13 Correct 120 ms 298068 KB Output is correct
14 Correct 130 ms 298132 KB Output is correct
15 Correct 123 ms 298076 KB Output is correct
16 Correct 124 ms 298188 KB Output is correct
17 Correct 122 ms 298012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 298060 KB Output is correct
2 Correct 125 ms 298088 KB Output is correct
3 Correct 131 ms 298060 KB Output is correct
4 Correct 134 ms 298060 KB Output is correct
5 Correct 120 ms 298092 KB Output is correct
6 Correct 119 ms 298076 KB Output is correct
7 Correct 116 ms 298032 KB Output is correct
8 Correct 122 ms 298064 KB Output is correct
9 Correct 130 ms 298112 KB Output is correct
10 Correct 131 ms 298072 KB Output is correct
11 Correct 134 ms 298108 KB Output is correct
12 Correct 125 ms 298008 KB Output is correct
13 Correct 120 ms 298068 KB Output is correct
14 Correct 130 ms 298132 KB Output is correct
15 Correct 123 ms 298076 KB Output is correct
16 Correct 124 ms 298188 KB Output is correct
17 Correct 122 ms 298012 KB Output is correct
18 Correct 123 ms 298116 KB Output is correct
19 Correct 125 ms 298064 KB Output is correct
20 Correct 123 ms 298060 KB Output is correct
21 Correct 122 ms 298008 KB Output is correct
22 Correct 124 ms 298048 KB Output is correct
23 Correct 138 ms 298092 KB Output is correct
24 Correct 133 ms 298000 KB Output is correct
25 Correct 126 ms 298032 KB Output is correct
26 Correct 124 ms 298100 KB Output is correct
27 Correct 129 ms 298064 KB Output is correct
28 Correct 128 ms 298044 KB Output is correct
29 Correct 121 ms 298044 KB Output is correct
30 Correct 133 ms 298060 KB Output is correct
31 Correct 123 ms 298068 KB Output is correct
32 Correct 125 ms 298052 KB Output is correct
33 Correct 126 ms 298024 KB Output is correct
34 Correct 124 ms 298124 KB Output is correct
35 Correct 124 ms 298036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 298060 KB Output is correct
2 Correct 125 ms 298088 KB Output is correct
3 Correct 131 ms 298060 KB Output is correct
4 Correct 134 ms 298060 KB Output is correct
5 Correct 120 ms 298092 KB Output is correct
6 Correct 119 ms 298076 KB Output is correct
7 Correct 116 ms 298032 KB Output is correct
8 Correct 122 ms 298064 KB Output is correct
9 Correct 130 ms 298112 KB Output is correct
10 Correct 131 ms 298072 KB Output is correct
11 Correct 134 ms 298108 KB Output is correct
12 Correct 125 ms 298008 KB Output is correct
13 Correct 120 ms 298068 KB Output is correct
14 Correct 130 ms 298132 KB Output is correct
15 Correct 123 ms 298076 KB Output is correct
16 Correct 124 ms 298188 KB Output is correct
17 Correct 122 ms 298012 KB Output is correct
18 Correct 143 ms 298176 KB Output is correct
19 Correct 131 ms 298136 KB Output is correct
20 Correct 127 ms 298060 KB Output is correct
21 Correct 129 ms 298076 KB Output is correct
22 Correct 138 ms 298056 KB Output is correct
23 Correct 129 ms 298024 KB Output is correct
24 Correct 122 ms 298004 KB Output is correct
25 Correct 126 ms 298052 KB Output is correct
26 Correct 126 ms 298004 KB Output is correct
27 Correct 129 ms 298124 KB Output is correct
28 Correct 123 ms 298028 KB Output is correct
29 Correct 129 ms 298068 KB Output is correct
30 Correct 128 ms 298096 KB Output is correct
31 Correct 127 ms 298136 KB Output is correct
32 Correct 120 ms 298068 KB Output is correct
33 Correct 132 ms 298020 KB Output is correct
34 Correct 130 ms 298024 KB Output is correct
35 Correct 125 ms 298068 KB Output is correct
36 Correct 119 ms 298000 KB Output is correct
37 Correct 123 ms 298128 KB Output is correct
38 Correct 121 ms 298132 KB Output is correct
39 Correct 143 ms 298124 KB Output is correct
40 Correct 129 ms 298080 KB Output is correct
41 Correct 151 ms 298116 KB Output is correct
42 Correct 129 ms 298076 KB Output is correct
43 Correct 153 ms 298084 KB Output is correct
44 Correct 146 ms 298016 KB Output is correct
45 Correct 143 ms 298076 KB Output is correct
46 Correct 130 ms 298124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 298060 KB Output is correct
2 Correct 125 ms 298088 KB Output is correct
3 Correct 131 ms 298060 KB Output is correct
4 Correct 134 ms 298060 KB Output is correct
5 Correct 120 ms 298092 KB Output is correct
6 Correct 119 ms 298076 KB Output is correct
7 Correct 116 ms 298032 KB Output is correct
8 Correct 122 ms 298064 KB Output is correct
9 Correct 130 ms 298112 KB Output is correct
10 Correct 131 ms 298072 KB Output is correct
11 Correct 134 ms 298108 KB Output is correct
12 Correct 125 ms 298008 KB Output is correct
13 Correct 120 ms 298068 KB Output is correct
14 Correct 130 ms 298132 KB Output is correct
15 Correct 123 ms 298076 KB Output is correct
16 Correct 124 ms 298188 KB Output is correct
17 Correct 122 ms 298012 KB Output is correct
18 Correct 123 ms 298116 KB Output is correct
19 Correct 125 ms 298064 KB Output is correct
20 Correct 123 ms 298060 KB Output is correct
21 Correct 122 ms 298008 KB Output is correct
22 Correct 124 ms 298048 KB Output is correct
23 Correct 138 ms 298092 KB Output is correct
24 Correct 133 ms 298000 KB Output is correct
25 Correct 126 ms 298032 KB Output is correct
26 Correct 124 ms 298100 KB Output is correct
27 Correct 129 ms 298064 KB Output is correct
28 Correct 128 ms 298044 KB Output is correct
29 Correct 121 ms 298044 KB Output is correct
30 Correct 133 ms 298060 KB Output is correct
31 Correct 123 ms 298068 KB Output is correct
32 Correct 125 ms 298052 KB Output is correct
33 Correct 126 ms 298024 KB Output is correct
34 Correct 124 ms 298124 KB Output is correct
35 Correct 124 ms 298036 KB Output is correct
36 Correct 143 ms 298176 KB Output is correct
37 Correct 131 ms 298136 KB Output is correct
38 Correct 127 ms 298060 KB Output is correct
39 Correct 129 ms 298076 KB Output is correct
40 Correct 138 ms 298056 KB Output is correct
41 Correct 129 ms 298024 KB Output is correct
42 Correct 122 ms 298004 KB Output is correct
43 Correct 126 ms 298052 KB Output is correct
44 Correct 126 ms 298004 KB Output is correct
45 Correct 129 ms 298124 KB Output is correct
46 Correct 123 ms 298028 KB Output is correct
47 Correct 129 ms 298068 KB Output is correct
48 Correct 128 ms 298096 KB Output is correct
49 Correct 127 ms 298136 KB Output is correct
50 Correct 120 ms 298068 KB Output is correct
51 Correct 132 ms 298020 KB Output is correct
52 Correct 130 ms 298024 KB Output is correct
53 Correct 125 ms 298068 KB Output is correct
54 Correct 119 ms 298000 KB Output is correct
55 Correct 123 ms 298128 KB Output is correct
56 Correct 121 ms 298132 KB Output is correct
57 Correct 143 ms 298124 KB Output is correct
58 Correct 129 ms 298080 KB Output is correct
59 Correct 151 ms 298116 KB Output is correct
60 Correct 129 ms 298076 KB Output is correct
61 Correct 153 ms 298084 KB Output is correct
62 Correct 146 ms 298016 KB Output is correct
63 Correct 143 ms 298076 KB Output is correct
64 Correct 130 ms 298124 KB Output is correct
65 Correct 180 ms 298064 KB Output is correct
66 Correct 140 ms 298028 KB Output is correct
67 Correct 137 ms 298072 KB Output is correct
68 Correct 137 ms 298140 KB Output is correct
69 Correct 148 ms 298132 KB Output is correct
70 Correct 140 ms 298120 KB Output is correct
71 Correct 138 ms 298028 KB Output is correct
72 Correct 155 ms 298080 KB Output is correct
73 Correct 151 ms 298008 KB Output is correct
74 Correct 134 ms 298092 KB Output is correct
75 Correct 142 ms 298080 KB Output is correct
76 Correct 155 ms 298144 KB Output is correct
77 Correct 143 ms 298112 KB Output is correct
78 Correct 135 ms 298004 KB Output is correct
79 Correct 146 ms 298064 KB Output is correct
80 Correct 154 ms 298060 KB Output is correct
81 Correct 136 ms 298340 KB Output is correct
82 Correct 137 ms 298088 KB Output is correct
83 Correct 147 ms 298016 KB Output is correct
84 Correct 140 ms 298048 KB Output is correct
85 Correct 159 ms 298120 KB Output is correct
86 Correct 141 ms 298144 KB Output is correct
87 Correct 150 ms 298120 KB Output is correct
88 Correct 145 ms 298028 KB Output is correct
89 Correct 143 ms 298132 KB Output is correct
90 Correct 144 ms 298248 KB Output is correct
91 Correct 147 ms 298044 KB Output is correct
92 Correct 146 ms 298060 KB Output is correct
93 Correct 136 ms 298060 KB Output is correct