Submission #856647

# Submission time Handle Problem Language Result Execution time Memory
856647 2023-10-04T07:24:58 Z 8pete8 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
124 ms 172376 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
//#include "combo.h"
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define pb push_back
#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int inf=1e18,mxn=222;
int dp[mxn][mxn][mxn][2],n,m;
int memo[mxn][mxn];
//at l r taken ,min time
vector<pii>v(mxn);
int caldist(int a,int b){
    //dist u->v;
    if(a>b)swap(a,b);
    int t1=a,t2=b;
    a=v[a].f,b=v[b].f;
    if(memo[t1][t2]!=-1)return memo[t1][t2];
    return memo[t1][t2]=min((b-a),m-b+a);
}
int32_t main(){
    cin>>n>>m;
    n++;
    v[0].f=0,v[0].s=0;
    for(int i=1;i<n;i++)cin>>v[i].f;
    for(int i=1;i<n;i++)cin>>v[i].s;
    for(int i=0;i<mxn;i++)for(int j=0;j<mxn;j++){
        memo[i][j]=-1;
        for(int k=0;k<mxn;k++)dp[i][j][k][0]=dp[i][j][k][1]=inf;
    }
    dp[0][0][0][0]=dp[0][0][0][1]=0;
    for(int sz=0;sz<n-1;sz++){
        int l,r=0,nr,nl;
        l=(n-sz)%n;
        bool yes=true;
        while(yes){
            if(l==0)yes=false;
            nr=(r+1)%n;
            nl=(l-1+n)%n;
            for(int t=0;t<=n;t++){
                if(dp[l][r][t][0]+caldist(nr,l)<=v[nr].s)dp[l][nr][t+1][1]=min(dp[l][nr][t+1][1],dp[l][r][t][0]+caldist(nr,l));
                else dp[l][nr][t][1]=min(dp[l][nr][t][1],dp[l][r][t][0]+caldist(nr,l));//l to nr
                if(dp[l][r][t][0]+caldist(l,nl)<=v[nl].s)dp[nl][r][t+1][0]=min(dp[nl][r][t+1][0],dp[l][r][t][0]+caldist(l,nl));
                else dp[nl][r][t][0]=min(dp[nl][r][t][0],dp[l][r][t][0]+caldist(l,nl));
                if(dp[l][r][t][1]+caldist(r,nl)<=v[nl].s)dp[nl][r][t+1][0]=min(dp[nl][r][t+1][0],dp[l][r][t][1]+caldist(r,nl));
                else dp[nl][r][t][0]=min(dp[nl][r][t][0],dp[l][r][t][1]+caldist(r,nl));
                if(dp[l][r][t][1]+caldist(nr,r)<=v[nr].s)dp[l][nr][t+1][1]=min(dp[l][nr][t+1][1],dp[l][r][t][1]+caldist(nr,r));
                else dp[l][nr][t][1]=min(dp[l][nr][t][1],dp[l][r][t][1]+caldist(nr,r));
            }
            r=nr;
            l=(l+1)%n;
        }
    }
    int ans=0;
    for(int i=0;i<mxn;i++)for(int j=0;j<mxn;j++)for(int k=0;k<mxn;k++)for(int g=0;g<2;g++)if(dp[i][j][k][g]<inf)ans=max(ans,k);
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 171856 KB Output is correct
2 Correct 39 ms 171856 KB Output is correct
3 Correct 39 ms 171860 KB Output is correct
4 Correct 39 ms 171860 KB Output is correct
5 Correct 39 ms 171856 KB Output is correct
6 Correct 39 ms 172376 KB Output is correct
7 Correct 39 ms 172124 KB Output is correct
8 Correct 40 ms 171896 KB Output is correct
9 Correct 39 ms 171868 KB Output is correct
10 Correct 39 ms 171856 KB Output is correct
11 Correct 39 ms 171856 KB Output is correct
12 Correct 40 ms 171948 KB Output is correct
13 Correct 40 ms 171956 KB Output is correct
14 Correct 39 ms 171924 KB Output is correct
15 Correct 38 ms 171868 KB Output is correct
16 Correct 42 ms 172088 KB Output is correct
17 Correct 39 ms 171856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 171856 KB Output is correct
2 Correct 39 ms 171856 KB Output is correct
3 Correct 39 ms 171860 KB Output is correct
4 Correct 39 ms 171860 KB Output is correct
5 Correct 39 ms 171856 KB Output is correct
6 Correct 39 ms 172376 KB Output is correct
7 Correct 39 ms 172124 KB Output is correct
8 Correct 40 ms 171896 KB Output is correct
9 Correct 39 ms 171868 KB Output is correct
10 Correct 39 ms 171856 KB Output is correct
11 Correct 39 ms 171856 KB Output is correct
12 Correct 40 ms 171948 KB Output is correct
13 Correct 40 ms 171956 KB Output is correct
14 Correct 39 ms 171924 KB Output is correct
15 Correct 38 ms 171868 KB Output is correct
16 Correct 42 ms 172088 KB Output is correct
17 Correct 39 ms 171856 KB Output is correct
18 Correct 39 ms 172004 KB Output is correct
19 Correct 38 ms 171856 KB Output is correct
20 Correct 39 ms 171892 KB Output is correct
21 Correct 39 ms 171860 KB Output is correct
22 Correct 39 ms 171868 KB Output is correct
23 Correct 39 ms 171860 KB Output is correct
24 Correct 41 ms 171864 KB Output is correct
25 Correct 39 ms 171908 KB Output is correct
26 Correct 38 ms 171868 KB Output is correct
27 Correct 39 ms 171864 KB Output is correct
28 Correct 42 ms 172300 KB Output is correct
29 Correct 39 ms 171868 KB Output is correct
30 Correct 38 ms 171912 KB Output is correct
31 Correct 39 ms 171944 KB Output is correct
32 Correct 39 ms 171868 KB Output is correct
33 Correct 39 ms 172084 KB Output is correct
34 Correct 40 ms 172092 KB Output is correct
35 Correct 38 ms 172076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 171856 KB Output is correct
2 Correct 39 ms 171856 KB Output is correct
3 Correct 39 ms 171860 KB Output is correct
4 Correct 39 ms 171860 KB Output is correct
5 Correct 39 ms 171856 KB Output is correct
6 Correct 39 ms 172376 KB Output is correct
7 Correct 39 ms 172124 KB Output is correct
8 Correct 40 ms 171896 KB Output is correct
9 Correct 39 ms 171868 KB Output is correct
10 Correct 39 ms 171856 KB Output is correct
11 Correct 39 ms 171856 KB Output is correct
12 Correct 40 ms 171948 KB Output is correct
13 Correct 40 ms 171956 KB Output is correct
14 Correct 39 ms 171924 KB Output is correct
15 Correct 38 ms 171868 KB Output is correct
16 Correct 42 ms 172088 KB Output is correct
17 Correct 39 ms 171856 KB Output is correct
18 Correct 98 ms 171868 KB Output is correct
19 Correct 65 ms 171860 KB Output is correct
20 Correct 51 ms 172088 KB Output is correct
21 Correct 64 ms 171868 KB Output is correct
22 Correct 82 ms 172116 KB Output is correct
23 Correct 48 ms 171908 KB Output is correct
24 Correct 47 ms 171868 KB Output is correct
25 Correct 47 ms 171860 KB Output is correct
26 Correct 41 ms 171856 KB Output is correct
27 Correct 48 ms 171868 KB Output is correct
28 Correct 47 ms 172124 KB Output is correct
29 Correct 48 ms 171864 KB Output is correct
30 Correct 45 ms 171904 KB Output is correct
31 Correct 50 ms 171864 KB Output is correct
32 Correct 42 ms 171868 KB Output is correct
33 Correct 49 ms 171860 KB Output is correct
34 Correct 41 ms 171868 KB Output is correct
35 Correct 47 ms 171868 KB Output is correct
36 Correct 41 ms 171864 KB Output is correct
37 Correct 47 ms 171868 KB Output is correct
38 Correct 45 ms 171860 KB Output is correct
39 Correct 47 ms 172044 KB Output is correct
40 Correct 44 ms 171868 KB Output is correct
41 Correct 115 ms 172088 KB Output is correct
42 Correct 82 ms 171864 KB Output is correct
43 Correct 118 ms 172088 KB Output is correct
44 Correct 81 ms 171864 KB Output is correct
45 Correct 124 ms 172088 KB Output is correct
46 Correct 78 ms 171868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 171856 KB Output is correct
2 Correct 39 ms 171856 KB Output is correct
3 Correct 39 ms 171860 KB Output is correct
4 Correct 39 ms 171860 KB Output is correct
5 Correct 39 ms 171856 KB Output is correct
6 Correct 39 ms 172376 KB Output is correct
7 Correct 39 ms 172124 KB Output is correct
8 Correct 40 ms 171896 KB Output is correct
9 Correct 39 ms 171868 KB Output is correct
10 Correct 39 ms 171856 KB Output is correct
11 Correct 39 ms 171856 KB Output is correct
12 Correct 40 ms 171948 KB Output is correct
13 Correct 40 ms 171956 KB Output is correct
14 Correct 39 ms 171924 KB Output is correct
15 Correct 38 ms 171868 KB Output is correct
16 Correct 42 ms 172088 KB Output is correct
17 Correct 39 ms 171856 KB Output is correct
18 Correct 39 ms 172004 KB Output is correct
19 Correct 38 ms 171856 KB Output is correct
20 Correct 39 ms 171892 KB Output is correct
21 Correct 39 ms 171860 KB Output is correct
22 Correct 39 ms 171868 KB Output is correct
23 Correct 39 ms 171860 KB Output is correct
24 Correct 41 ms 171864 KB Output is correct
25 Correct 39 ms 171908 KB Output is correct
26 Correct 38 ms 171868 KB Output is correct
27 Correct 39 ms 171864 KB Output is correct
28 Correct 42 ms 172300 KB Output is correct
29 Correct 39 ms 171868 KB Output is correct
30 Correct 38 ms 171912 KB Output is correct
31 Correct 39 ms 171944 KB Output is correct
32 Correct 39 ms 171868 KB Output is correct
33 Correct 39 ms 172084 KB Output is correct
34 Correct 40 ms 172092 KB Output is correct
35 Correct 38 ms 172076 KB Output is correct
36 Correct 98 ms 171868 KB Output is correct
37 Correct 65 ms 171860 KB Output is correct
38 Correct 51 ms 172088 KB Output is correct
39 Correct 64 ms 171868 KB Output is correct
40 Correct 82 ms 172116 KB Output is correct
41 Correct 48 ms 171908 KB Output is correct
42 Correct 47 ms 171868 KB Output is correct
43 Correct 47 ms 171860 KB Output is correct
44 Correct 41 ms 171856 KB Output is correct
45 Correct 48 ms 171868 KB Output is correct
46 Correct 47 ms 172124 KB Output is correct
47 Correct 48 ms 171864 KB Output is correct
48 Correct 45 ms 171904 KB Output is correct
49 Correct 50 ms 171864 KB Output is correct
50 Correct 42 ms 171868 KB Output is correct
51 Correct 49 ms 171860 KB Output is correct
52 Correct 41 ms 171868 KB Output is correct
53 Correct 47 ms 171868 KB Output is correct
54 Correct 41 ms 171864 KB Output is correct
55 Correct 47 ms 171868 KB Output is correct
56 Correct 45 ms 171860 KB Output is correct
57 Correct 47 ms 172044 KB Output is correct
58 Correct 44 ms 171868 KB Output is correct
59 Correct 115 ms 172088 KB Output is correct
60 Correct 82 ms 171864 KB Output is correct
61 Correct 118 ms 172088 KB Output is correct
62 Correct 81 ms 171864 KB Output is correct
63 Correct 124 ms 172088 KB Output is correct
64 Correct 78 ms 171868 KB Output is correct
65 Correct 110 ms 172088 KB Output is correct
66 Correct 100 ms 172084 KB Output is correct
67 Correct 96 ms 172084 KB Output is correct
68 Correct 85 ms 172084 KB Output is correct
69 Correct 108 ms 171868 KB Output is correct
70 Correct 107 ms 171856 KB Output is correct
71 Correct 102 ms 171856 KB Output is correct
72 Correct 106 ms 171864 KB Output is correct
73 Correct 100 ms 171864 KB Output is correct
74 Correct 91 ms 171908 KB Output is correct
75 Correct 95 ms 171856 KB Output is correct
76 Correct 116 ms 172112 KB Output is correct
77 Correct 110 ms 171868 KB Output is correct
78 Correct 90 ms 171888 KB Output is correct
79 Correct 86 ms 171868 KB Output is correct
80 Correct 116 ms 172088 KB Output is correct
81 Correct 94 ms 171868 KB Output is correct
82 Correct 92 ms 171860 KB Output is correct
83 Correct 111 ms 171868 KB Output is correct
84 Correct 107 ms 172092 KB Output is correct
85 Correct 107 ms 171864 KB Output is correct
86 Correct 111 ms 171864 KB Output is correct
87 Correct 100 ms 172088 KB Output is correct
88 Correct 116 ms 172088 KB Output is correct
89 Correct 117 ms 172116 KB Output is correct
90 Correct 99 ms 171868 KB Output is correct
91 Correct 113 ms 172028 KB Output is correct
92 Correct 123 ms 172112 KB Output is correct
93 Correct 117 ms 172360 KB Output is correct