Submission #788258

# Submission time Handle Problem Language Result Execution time Memory
788258 2023-07-20T03:56:29 Z winter0101 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
61 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 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 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 1 ms 340 KB Output is correct
15 Correct 1 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 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 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 1 ms 340 KB Output is correct
15 Correct 1 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 712 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 724 KB Output is correct
22 Correct 1 ms 452 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 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 584 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 724 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 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 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 1 ms 340 KB Output is correct
15 Correct 1 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 43 ms 51952 KB Output is correct
19 Correct 26 ms 31560 KB Output is correct
20 Correct 14 ms 17040 KB Output is correct
21 Correct 25 ms 29936 KB Output is correct
22 Correct 34 ms 38664 KB Output is correct
23 Correct 11 ms 14548 KB Output is correct
24 Correct 10 ms 11448 KB Output is correct
25 Correct 10 ms 14164 KB Output is correct
26 Correct 3 ms 5588 KB Output is correct
27 Correct 13 ms 14848 KB Output is correct
28 Correct 6 ms 10580 KB Output is correct
29 Correct 11 ms 15048 KB Output is correct
30 Correct 7 ms 11860 KB Output is correct
31 Correct 11 ms 14164 KB Output is correct
32 Correct 4 ms 7496 KB Output is correct
33 Correct 11 ms 14260 KB Output is correct
34 Correct 3 ms 5204 KB Output is correct
35 Correct 9 ms 13908 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 8272 KB Output is correct
39 Correct 11 ms 15444 KB Output is correct
40 Correct 5 ms 9156 KB Output is correct
41 Correct 59 ms 63572 KB Output is correct
42 Correct 31 ms 43260 KB Output is correct
43 Correct 60 ms 63564 KB Output is correct
44 Correct 30 ms 42684 KB Output is correct
45 Correct 61 ms 63576 KB Output is correct
46 Correct 34 ms 43360 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 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 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 1 ms 340 KB Output is correct
15 Correct 1 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 712 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 724 KB Output is correct
22 Correct 1 ms 452 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 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 584 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 724 KB Output is correct
36 Correct 43 ms 51952 KB Output is correct
37 Correct 26 ms 31560 KB Output is correct
38 Correct 14 ms 17040 KB Output is correct
39 Correct 25 ms 29936 KB Output is correct
40 Correct 34 ms 38664 KB Output is correct
41 Correct 11 ms 14548 KB Output is correct
42 Correct 10 ms 11448 KB Output is correct
43 Correct 10 ms 14164 KB Output is correct
44 Correct 3 ms 5588 KB Output is correct
45 Correct 13 ms 14848 KB Output is correct
46 Correct 6 ms 10580 KB Output is correct
47 Correct 11 ms 15048 KB Output is correct
48 Correct 7 ms 11860 KB Output is correct
49 Correct 11 ms 14164 KB Output is correct
50 Correct 4 ms 7496 KB Output is correct
51 Correct 11 ms 14260 KB Output is correct
52 Correct 3 ms 5204 KB Output is correct
53 Correct 9 ms 13908 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 8272 KB Output is correct
57 Correct 11 ms 15444 KB Output is correct
58 Correct 5 ms 9156 KB Output is correct
59 Correct 59 ms 63572 KB Output is correct
60 Correct 31 ms 43260 KB Output is correct
61 Correct 60 ms 63564 KB Output is correct
62 Correct 30 ms 42684 KB Output is correct
63 Correct 61 ms 63576 KB Output is correct
64 Correct 34 ms 43360 KB Output is correct
65 Correct 44 ms 57824 KB Output is correct
66 Correct 39 ms 53136 KB Output is correct
67 Correct 42 ms 50768 KB Output is correct
68 Correct 34 ms 46996 KB Output is correct
69 Correct 44 ms 57384 KB Output is correct
70 Correct 42 ms 54888 KB Output is correct
71 Correct 41 ms 55444 KB Output is correct
72 Correct 43 ms 56000 KB Output is correct
73 Correct 37 ms 51924 KB Output is correct
74 Correct 37 ms 48572 KB Output is correct
75 Correct 39 ms 53712 KB Output is correct
76 Correct 52 ms 61528 KB Output is correct
77 Correct 53 ms 61584 KB Output is correct
78 Correct 38 ms 47516 KB Output is correct
79 Correct 36 ms 49164 KB Output is correct
80 Correct 50 ms 60288 KB Output is correct
81 Correct 37 ms 49724 KB Output is correct
82 Correct 42 ms 52436 KB Output is correct
83 Correct 49 ms 63556 KB Output is correct
84 Correct 43 ms 54868 KB Output is correct
85 Correct 44 ms 59676 KB Output is correct
86 Correct 50 ms 58492 KB Output is correct
87 Correct 44 ms 53716 KB Output is correct
88 Correct 52 ms 63820 KB Output is correct
89 Correct 50 ms 63864 KB Output is correct
90 Correct 39 ms 54220 KB Output is correct
91 Correct 54 ms 63868 KB Output is correct
92 Correct 49 ms 63872 KB Output is correct
93 Correct 46 ms 63240 KB Output is correct