Submission #788219

# Submission time Handle Problem Language Result Execution time Memory
788219 2023-07-20T02:24:43 Z vjudge1 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
62 ms 63872 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int inf=1e9+2;
int dp[201][201][201][2];
int x[201],t[201],y[201];
int n;
int run(int pos){
if (pos==0)return n;
return pos-1;
}
int nur(int pos){
if (pos==n)return 0;
return pos+1;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    long long l;
    cin>>n>>l;
    for1(i,1,n){
    cin>>x[i];
    y[i]=l-x[i];
    }
    for1(i,1,n){
    cin>>t[i];
    }
    for1(i,0,n){
    for1(j,0,n){
    for1(k,0,n){
    dp[i][j][k][0]=dp[i][j][k][1]=inf;
    }
    }
    }
    dp[0][0][0][0]=dp[0][0][0][1]=0;
    //cout<<dp[0][1][2][0]<<'\n';
    for1(i,0,0){
    for1(j,0,n){
    if (i!=0&&i<j)continue;
    for2(k,n,0){
    for1(turn,0,1){
    if (dp[i][j][k][turn]>=inf)continue;
    if (i==j&&i!=0)continue;
    if (j==n)continue;
    if (i==1)continue;
    //cout<<k<<'\n';
    //cout<<i<<" "<<j<<" "<<k<<" "<<turn<<" "<<dp[i][j][k][turn]<<'\n';
    if (turn){
        //on i
        //go i
        int nxt=run(i);
        int newcost,newk;
        if (nxt!=j){
        newcost=min(inf,dp[i][j][k][turn]+y[nxt]-y[i]);
        newk=k;
        if (newcost<=t[nxt])newk++;
        dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
        }
        //go j
        nxt=nur(j);
        if (nxt!=i){
        newcost=min(inf,dp[i][j][k][turn]+y[i]+x[nxt]);
        newk=k;
        if (newcost<=t[nxt])newk++;
        dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
        }
    }
    else {
        //on j
        //go i
        int nxt=run(i),newcost,newk;
        if (nxt!=j){
        newcost=min(inf,dp[i][j][k][turn]+x[j]+y[nxt]);
        newk=k;
        if (newcost<=t[nxt])newk++;
        dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
        }
        //go j
        nxt=nur(j);
        if (nxt!=i){
        newk=k;
        newcost=min(inf,dp[i][j][k][turn]+x[nxt]-x[j]);
        if (newcost<=t[nxt])newk++;
        dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
        }
    }
    }
    }
    }
    }
    //cout<<dp[0][1][2][0];
    for2(i,n,1){
    for1(j,0,n){
    if (i!=0&&i<j)continue;
    for2(k,n,0){
    for1(turn,0,1){
    if (dp[i][j][k][turn]>=inf)continue;
    if (i==j&&i!=0)continue;
    if (j==n)continue;
    if (i==1)continue;
    if (turn){
        //on i
        //go i
        int nxt=run(i);
        int newcost,newk;
        if (nxt!=j){
        newcost=min(inf,dp[i][j][k][turn]+y[nxt]-y[i]);
        newk=k;
        if (newcost<=t[nxt])newk++;
        dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
        }
        //go j
        nxt=nur(j);
        if (nxt!=i){
        newcost=min(inf,dp[i][j][k][turn]+y[i]+x[nxt]);
        newk=k;
        if (newcost<=t[nxt])newk++;
        dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
        }
    }
    else {
        //on j
        //go i
        int nxt=run(i),newcost,newk;
        if (nxt!=j){
        newcost=min(inf,dp[i][j][k][turn]+x[j]+y[nxt]);
        newk=k;
        if (newcost<=t[nxt])newk++;
        dp[nxt][j][newk][1]=min(dp[nxt][j][newk][1],newcost);
        }
        //go j
        nxt=nur(j);
        if (nxt!=i){
        newk=k;
        newcost=min(inf,dp[i][j][k][turn]+x[nxt]-x[j]);
        if (newcost<=t[nxt])newk++;
        dp[i][nxt][newk][0]=min(dp[i][nxt][newk][0],newcost);
        }
    }
    }
    }
    }
    }
    int ans=0;
    for1(i,0,n){
    for1(j,0,n){
    for1(k,1,n){
    for1(l1,0,1){
    if (dp[i][j][k][l1]>=inf)continue;
    ans=max(ans,k);
    //if (k==12)cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k][l1]<<'\n';
    }
    }
    }
    }
    cout<<ans;
    //cout<<dp[0][1][1][0];

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 712 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 712 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 708 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 712 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 724 KB Output is correct
35 Correct 1 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 44 ms 51916 KB Output is correct
19 Correct 26 ms 31620 KB Output is correct
20 Correct 12 ms 16980 KB Output is correct
21 Correct 25 ms 29908 KB Output is correct
22 Correct 32 ms 38612 KB Output is correct
23 Correct 11 ms 14548 KB Output is correct
24 Correct 7 ms 11336 KB Output is correct
25 Correct 10 ms 14164 KB Output is correct
26 Correct 3 ms 5588 KB Output is correct
27 Correct 11 ms 14804 KB Output is correct
28 Correct 7 ms 10680 KB Output is correct
29 Correct 10 ms 15060 KB Output is correct
30 Correct 7 ms 11972 KB Output is correct
31 Correct 9 ms 14260 KB Output is correct
32 Correct 5 ms 7508 KB Output is correct
33 Correct 9 ms 14260 KB Output is correct
34 Correct 3 ms 5188 KB Output is correct
35 Correct 10 ms 13968 KB Output is correct
36 Correct 4 ms 6740 KB Output is correct
37 Correct 10 ms 14804 KB Output is correct
38 Correct 5 ms 8264 KB Output is correct
39 Correct 10 ms 15444 KB Output is correct
40 Correct 5 ms 9172 KB Output is correct
41 Correct 61 ms 63552 KB Output is correct
42 Correct 27 ms 43264 KB Output is correct
43 Correct 60 ms 63452 KB Output is correct
44 Correct 29 ms 42684 KB Output is correct
45 Correct 62 ms 63444 KB Output is correct
46 Correct 31 ms 43200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 712 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 712 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 708 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 712 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 724 KB Output is correct
35 Correct 1 ms 712 KB Output is correct
36 Correct 44 ms 51916 KB Output is correct
37 Correct 26 ms 31620 KB Output is correct
38 Correct 12 ms 16980 KB Output is correct
39 Correct 25 ms 29908 KB Output is correct
40 Correct 32 ms 38612 KB Output is correct
41 Correct 11 ms 14548 KB Output is correct
42 Correct 7 ms 11336 KB Output is correct
43 Correct 10 ms 14164 KB Output is correct
44 Correct 3 ms 5588 KB Output is correct
45 Correct 11 ms 14804 KB Output is correct
46 Correct 7 ms 10680 KB Output is correct
47 Correct 10 ms 15060 KB Output is correct
48 Correct 7 ms 11972 KB Output is correct
49 Correct 9 ms 14260 KB Output is correct
50 Correct 5 ms 7508 KB Output is correct
51 Correct 9 ms 14260 KB Output is correct
52 Correct 3 ms 5188 KB Output is correct
53 Correct 10 ms 13968 KB Output is correct
54 Correct 4 ms 6740 KB Output is correct
55 Correct 10 ms 14804 KB Output is correct
56 Correct 5 ms 8264 KB Output is correct
57 Correct 10 ms 15444 KB Output is correct
58 Correct 5 ms 9172 KB Output is correct
59 Correct 61 ms 63552 KB Output is correct
60 Correct 27 ms 43264 KB Output is correct
61 Correct 60 ms 63452 KB Output is correct
62 Correct 29 ms 42684 KB Output is correct
63 Correct 62 ms 63444 KB Output is correct
64 Correct 31 ms 43200 KB Output is correct
65 Correct 43 ms 57824 KB Output is correct
66 Correct 40 ms 53076 KB Output is correct
67 Correct 39 ms 50772 KB Output is correct
68 Correct 35 ms 46932 KB Output is correct
69 Correct 44 ms 57172 KB Output is correct
70 Correct 52 ms 54884 KB Output is correct
71 Correct 41 ms 55552 KB Output is correct
72 Correct 41 ms 56012 KB Output is correct
73 Correct 37 ms 51996 KB Output is correct
74 Correct 36 ms 48528 KB Output is correct
75 Correct 38 ms 53716 KB Output is correct
76 Correct 50 ms 61424 KB Output is correct
77 Correct 45 ms 61524 KB Output is correct
78 Correct 36 ms 47444 KB Output is correct
79 Correct 35 ms 49108 KB Output is correct
80 Correct 53 ms 60292 KB Output is correct
81 Correct 35 ms 49732 KB Output is correct
82 Correct 41 ms 52556 KB Output is correct
83 Correct 47 ms 63576 KB Output is correct
84 Correct 51 ms 54832 KB Output is correct
85 Correct 44 ms 59680 KB Output is correct
86 Correct 46 ms 58452 KB Output is correct
87 Correct 46 ms 53720 KB Output is correct
88 Correct 62 ms 63768 KB Output is correct
89 Correct 50 ms 63868 KB Output is correct
90 Correct 40 ms 54228 KB Output is correct
91 Correct 53 ms 63872 KB Output is correct
92 Correct 49 ms 63872 KB Output is correct
93 Correct 45 ms 63232 KB Output is correct