Submission #224028

# Submission time Handle Problem Language Result Execution time Memory
224028 2020-04-17T05:23:49 Z errorgorn Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
280 ms 135436 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=start-(start>end);x!=end-(start>end);x+=(start<end?1:-1))
#define all(x) x.begin(),x.end()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a, Args... args) { return max(a,MAX(args...)); }
template<typename... Args>
ll MIN(ll a, Args... args) { return min(a,MIN(args...)); }

#define indexed_set tree<ll, null_type, less<ll>,rb_tree_tag,tree_order_statistics_node_update>

const ll INF=1e18;

int n,l;
ll pos[205];
ll t[205];
ll memo[2][205][205][205];

ll dp(int par,int l,int r,int taken){
	if (memo[par][l][r][taken]!=-1) return memo[par][l][r][taken];
	
	ll res=INF;
	//try dont take anything
	if (par==0 && l!=0){
		res=MIN(res,dp(0,l-1,r,taken)+pos[l]-pos[l-1],dp(1,l-1,r,taken)+pos[l]+(pos[n+1]-pos[r]));
	}
	else if (par==1 && r!=n+1){
		res=MIN(res,dp(1,l,r+1,taken)+pos[r+1]-pos[r],dp(0,l,r+1,taken)+(pos[n+1]-pos[r])+pos[l]);
	}
	
	//now try increase taken by 1
	ll tim;
	if (taken){
		if (par==0 && l!=0){
			tim=dp(0,l-1,r,taken-1)+pos[l]-pos[l-1];
			if (tim<=t[l]) res=min(res,tim);
			tim=dp(1,l-1,r,taken-1)+pos[l]+(pos[n+1]-pos[r]);
			if (tim<=t[l]) res=min(res,tim);
		}
		else if (par==1 && r!=n+1){
			tim=dp(1,l,r+1,taken-1)+pos[r+1]-pos[r];
			if (tim<=t[r]) res=min(res,tim);
			tim=dp(0,l,r+1,taken-1)+(pos[n+1]-pos[r])+pos[l];
			if (tim<=t[r]) res=min(res,tim);
		}
	}
	
	//cout<<par<<" "<<l<<" "<<r<<" "<<taken<<" "<<res<<endl;
	return memo[par][l][r][taken]=res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>l;
	pos[0]=0,pos[n+1]=l;
	rep(x,1,n+1) cin>>pos[x];
	rep(x,1,n+1) cin>>t[x];
	
	memset(memo,-1,sizeof(memo));
	
	memo[0][0][n+1][0]=0;
	memo[1][0][n+1][0]=0;
	
	int ans=0;
	rep(x,0,n+1)
		rep(y,0,n+1)
			if (dp(0,x,x+1,y)<INF || dp(1,x,x+1,y)<INF) ans=max(ans,y);
	
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 64 ms 135160 KB Output is correct
2 Correct 66 ms 135164 KB Output is correct
3 Correct 64 ms 135160 KB Output is correct
4 Correct 66 ms 135160 KB Output is correct
5 Correct 64 ms 135160 KB Output is correct
6 Correct 65 ms 135160 KB Output is correct
7 Correct 65 ms 135288 KB Output is correct
8 Correct 69 ms 135288 KB Output is correct
9 Correct 63 ms 135160 KB Output is correct
10 Correct 64 ms 135164 KB Output is correct
11 Correct 65 ms 135160 KB Output is correct
12 Correct 64 ms 135160 KB Output is correct
13 Correct 64 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 64 ms 135160 KB Output is correct
16 Correct 64 ms 135288 KB Output is correct
17 Correct 64 ms 135288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 135160 KB Output is correct
2 Correct 66 ms 135164 KB Output is correct
3 Correct 64 ms 135160 KB Output is correct
4 Correct 66 ms 135160 KB Output is correct
5 Correct 64 ms 135160 KB Output is correct
6 Correct 65 ms 135160 KB Output is correct
7 Correct 65 ms 135288 KB Output is correct
8 Correct 69 ms 135288 KB Output is correct
9 Correct 63 ms 135160 KB Output is correct
10 Correct 64 ms 135164 KB Output is correct
11 Correct 65 ms 135160 KB Output is correct
12 Correct 64 ms 135160 KB Output is correct
13 Correct 64 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 64 ms 135160 KB Output is correct
16 Correct 64 ms 135288 KB Output is correct
17 Correct 64 ms 135288 KB Output is correct
18 Correct 64 ms 135160 KB Output is correct
19 Correct 66 ms 135160 KB Output is correct
20 Correct 72 ms 135288 KB Output is correct
21 Correct 69 ms 135288 KB Output is correct
22 Correct 69 ms 135160 KB Output is correct
23 Correct 66 ms 135160 KB Output is correct
24 Correct 65 ms 135160 KB Output is correct
25 Correct 64 ms 135160 KB Output is correct
26 Correct 72 ms 135288 KB Output is correct
27 Correct 64 ms 135288 KB Output is correct
28 Correct 63 ms 135288 KB Output is correct
29 Correct 65 ms 135200 KB Output is correct
30 Correct 71 ms 135288 KB Output is correct
31 Correct 64 ms 135288 KB Output is correct
32 Correct 65 ms 135160 KB Output is correct
33 Correct 64 ms 135160 KB Output is correct
34 Correct 65 ms 135160 KB Output is correct
35 Correct 63 ms 135160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 135160 KB Output is correct
2 Correct 66 ms 135164 KB Output is correct
3 Correct 64 ms 135160 KB Output is correct
4 Correct 66 ms 135160 KB Output is correct
5 Correct 64 ms 135160 KB Output is correct
6 Correct 65 ms 135160 KB Output is correct
7 Correct 65 ms 135288 KB Output is correct
8 Correct 69 ms 135288 KB Output is correct
9 Correct 63 ms 135160 KB Output is correct
10 Correct 64 ms 135164 KB Output is correct
11 Correct 65 ms 135160 KB Output is correct
12 Correct 64 ms 135160 KB Output is correct
13 Correct 64 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 64 ms 135160 KB Output is correct
16 Correct 64 ms 135288 KB Output is correct
17 Correct 64 ms 135288 KB Output is correct
18 Correct 195 ms 135288 KB Output is correct
19 Correct 150 ms 135160 KB Output is correct
20 Correct 89 ms 135160 KB Output is correct
21 Correct 119 ms 135160 KB Output is correct
22 Correct 167 ms 135288 KB Output is correct
23 Correct 93 ms 135288 KB Output is correct
24 Correct 84 ms 135288 KB Output is correct
25 Correct 85 ms 135208 KB Output is correct
26 Correct 70 ms 135288 KB Output is correct
27 Correct 93 ms 135288 KB Output is correct
28 Correct 76 ms 135288 KB Output is correct
29 Correct 94 ms 135264 KB Output is correct
30 Correct 80 ms 135288 KB Output is correct
31 Correct 98 ms 135436 KB Output is correct
32 Correct 82 ms 135160 KB Output is correct
33 Correct 83 ms 135260 KB Output is correct
34 Correct 67 ms 135164 KB Output is correct
35 Correct 81 ms 135160 KB Output is correct
36 Correct 79 ms 135288 KB Output is correct
37 Correct 90 ms 135288 KB Output is correct
38 Correct 79 ms 135288 KB Output is correct
39 Correct 95 ms 135288 KB Output is correct
40 Correct 71 ms 135160 KB Output is correct
41 Correct 251 ms 135288 KB Output is correct
42 Correct 147 ms 135160 KB Output is correct
43 Correct 251 ms 135160 KB Output is correct
44 Correct 158 ms 135164 KB Output is correct
45 Correct 271 ms 135160 KB Output is correct
46 Correct 165 ms 135288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 135160 KB Output is correct
2 Correct 66 ms 135164 KB Output is correct
3 Correct 64 ms 135160 KB Output is correct
4 Correct 66 ms 135160 KB Output is correct
5 Correct 64 ms 135160 KB Output is correct
6 Correct 65 ms 135160 KB Output is correct
7 Correct 65 ms 135288 KB Output is correct
8 Correct 69 ms 135288 KB Output is correct
9 Correct 63 ms 135160 KB Output is correct
10 Correct 64 ms 135164 KB Output is correct
11 Correct 65 ms 135160 KB Output is correct
12 Correct 64 ms 135160 KB Output is correct
13 Correct 64 ms 135160 KB Output is correct
14 Correct 70 ms 135160 KB Output is correct
15 Correct 64 ms 135160 KB Output is correct
16 Correct 64 ms 135288 KB Output is correct
17 Correct 64 ms 135288 KB Output is correct
18 Correct 64 ms 135160 KB Output is correct
19 Correct 66 ms 135160 KB Output is correct
20 Correct 72 ms 135288 KB Output is correct
21 Correct 69 ms 135288 KB Output is correct
22 Correct 69 ms 135160 KB Output is correct
23 Correct 66 ms 135160 KB Output is correct
24 Correct 65 ms 135160 KB Output is correct
25 Correct 64 ms 135160 KB Output is correct
26 Correct 72 ms 135288 KB Output is correct
27 Correct 64 ms 135288 KB Output is correct
28 Correct 63 ms 135288 KB Output is correct
29 Correct 65 ms 135200 KB Output is correct
30 Correct 71 ms 135288 KB Output is correct
31 Correct 64 ms 135288 KB Output is correct
32 Correct 65 ms 135160 KB Output is correct
33 Correct 64 ms 135160 KB Output is correct
34 Correct 65 ms 135160 KB Output is correct
35 Correct 63 ms 135160 KB Output is correct
36 Correct 195 ms 135288 KB Output is correct
37 Correct 150 ms 135160 KB Output is correct
38 Correct 89 ms 135160 KB Output is correct
39 Correct 119 ms 135160 KB Output is correct
40 Correct 167 ms 135288 KB Output is correct
41 Correct 93 ms 135288 KB Output is correct
42 Correct 84 ms 135288 KB Output is correct
43 Correct 85 ms 135208 KB Output is correct
44 Correct 70 ms 135288 KB Output is correct
45 Correct 93 ms 135288 KB Output is correct
46 Correct 76 ms 135288 KB Output is correct
47 Correct 94 ms 135264 KB Output is correct
48 Correct 80 ms 135288 KB Output is correct
49 Correct 98 ms 135436 KB Output is correct
50 Correct 82 ms 135160 KB Output is correct
51 Correct 83 ms 135260 KB Output is correct
52 Correct 67 ms 135164 KB Output is correct
53 Correct 81 ms 135160 KB Output is correct
54 Correct 79 ms 135288 KB Output is correct
55 Correct 90 ms 135288 KB Output is correct
56 Correct 79 ms 135288 KB Output is correct
57 Correct 95 ms 135288 KB Output is correct
58 Correct 71 ms 135160 KB Output is correct
59 Correct 251 ms 135288 KB Output is correct
60 Correct 147 ms 135160 KB Output is correct
61 Correct 251 ms 135160 KB Output is correct
62 Correct 158 ms 135164 KB Output is correct
63 Correct 271 ms 135160 KB Output is correct
64 Correct 165 ms 135288 KB Output is correct
65 Correct 226 ms 135160 KB Output is correct
66 Correct 205 ms 135288 KB Output is correct
67 Correct 213 ms 135160 KB Output is correct
68 Correct 181 ms 135160 KB Output is correct
69 Correct 216 ms 135164 KB Output is correct
70 Correct 214 ms 135160 KB Output is correct
71 Correct 213 ms 135160 KB Output is correct
72 Correct 223 ms 135160 KB Output is correct
73 Correct 183 ms 135288 KB Output is correct
74 Correct 215 ms 135160 KB Output is correct
75 Correct 207 ms 135200 KB Output is correct
76 Correct 264 ms 135160 KB Output is correct
77 Correct 233 ms 135288 KB Output is correct
78 Correct 181 ms 135416 KB Output is correct
79 Correct 207 ms 135160 KB Output is correct
80 Correct 229 ms 135288 KB Output is correct
81 Correct 180 ms 135160 KB Output is correct
82 Correct 212 ms 135160 KB Output is correct
83 Correct 239 ms 135288 KB Output is correct
84 Correct 228 ms 135160 KB Output is correct
85 Correct 230 ms 135160 KB Output is correct
86 Correct 232 ms 135160 KB Output is correct
87 Correct 208 ms 135160 KB Output is correct
88 Correct 257 ms 135160 KB Output is correct
89 Correct 261 ms 135160 KB Output is correct
90 Correct 186 ms 135160 KB Output is correct
91 Correct 280 ms 135288 KB Output is correct
92 Correct 261 ms 135416 KB Output is correct
93 Correct 212 ms 135160 KB Output is correct