Submission #445862

# Submission time Handle Problem Language Result Execution time Memory
445862 2021-07-20T00:49:23 Z jamezzz Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
545 ms 135276 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
mt19937 rng(time(0));

#define maxn 205

int n,l,x[maxn];ll t[maxn];
ll memo[maxn][maxn][maxn][2];

int dist(int a,int b){
	return min(abs(x[a]-x[b]),l-abs(x[a]-x[b]));
}

//visited from l to r, want to take k more, at side s
//returns earliest time u need to leave
ll dp(int l,int r,int k,int s){
	if(k==0)return LINF;
	if(r+1==l)return -LINF;
	if(memo[l][r][k][s]!=-1)return memo[l][r][k][s];
	ll res=-LINF;
	if(s==0){//at l
		res=max(res,min(t[l-1],dp(l-1,r,k-1,0))-dist(l-1,l));//go to left, take
		res=max(res,dp(l-1,r,k,0)-dist(l-1,l));//go to left, dont take
		res=max(res,min(t[r+1],dp(l,r+1,k-1,1))-dist(l,r+1));//go to right, take
		res=max(res,dp(l,r+1,k,1)-dist(l,r+1));//go to right, dont take
	}
	else{
		res=max(res,min(t[l-1],dp(l-1,r,k-1,0))-dist(l-1,r));//go to left, take
		res=max(res,dp(l-1,r,k,0)-dist(l-1,r));//go to left, dont take
		res=max(res,min(t[r+1],dp(l,r+1,k-1,1))-dist(r,r+1));//go to right, take
		res=max(res,dp(l,r+1,k,1)-dist(r,r+1));//go to right, dont take
	}
	return memo[l][r][k][s]=res;
}

int main(){
	sf("%d%d",&n,&l);
	for(int i=1;i<=n;++i){
		sf("%d",&x[i]);
	}
	for(int i=1;i<=n;++i){
		sf("%lld",&t[i]);
	}
	memset(memo,-1,sizeof memo);
	int ans=0;
	for(int k=0;k<=n;++k){
		if(dp(n+1,0,k,0)>=0)ans=k;
	}
	pf("%d\n",ans);
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:57:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |  sf("%d%d",&n,&l);
      |    ^
ho_t3.cpp:59:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   sf("%d",&x[i]);
      |     ^
ho_t3.cpp:62:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   sf("%lld",&t[i]);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 58 ms 135060 KB Output is correct
2 Correct 59 ms 135056 KB Output is correct
3 Correct 57 ms 135044 KB Output is correct
4 Correct 55 ms 135108 KB Output is correct
5 Correct 57 ms 135108 KB Output is correct
6 Correct 57 ms 135088 KB Output is correct
7 Correct 57 ms 135120 KB Output is correct
8 Correct 57 ms 135124 KB Output is correct
9 Correct 58 ms 135108 KB Output is correct
10 Correct 57 ms 135088 KB Output is correct
11 Correct 58 ms 135036 KB Output is correct
12 Correct 57 ms 135108 KB Output is correct
13 Correct 58 ms 135108 KB Output is correct
14 Correct 59 ms 135112 KB Output is correct
15 Correct 57 ms 135080 KB Output is correct
16 Correct 58 ms 135160 KB Output is correct
17 Correct 56 ms 135108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 135060 KB Output is correct
2 Correct 59 ms 135056 KB Output is correct
3 Correct 57 ms 135044 KB Output is correct
4 Correct 55 ms 135108 KB Output is correct
5 Correct 57 ms 135108 KB Output is correct
6 Correct 57 ms 135088 KB Output is correct
7 Correct 57 ms 135120 KB Output is correct
8 Correct 57 ms 135124 KB Output is correct
9 Correct 58 ms 135108 KB Output is correct
10 Correct 57 ms 135088 KB Output is correct
11 Correct 58 ms 135036 KB Output is correct
12 Correct 57 ms 135108 KB Output is correct
13 Correct 58 ms 135108 KB Output is correct
14 Correct 59 ms 135112 KB Output is correct
15 Correct 57 ms 135080 KB Output is correct
16 Correct 58 ms 135160 KB Output is correct
17 Correct 56 ms 135108 KB Output is correct
18 Correct 58 ms 135104 KB Output is correct
19 Correct 61 ms 135076 KB Output is correct
20 Correct 59 ms 135108 KB Output is correct
21 Correct 59 ms 135140 KB Output is correct
22 Correct 55 ms 135116 KB Output is correct
23 Correct 57 ms 135108 KB Output is correct
24 Correct 57 ms 135112 KB Output is correct
25 Correct 58 ms 135108 KB Output is correct
26 Correct 57 ms 135112 KB Output is correct
27 Correct 58 ms 135140 KB Output is correct
28 Correct 59 ms 135040 KB Output is correct
29 Correct 57 ms 135144 KB Output is correct
30 Correct 56 ms 135080 KB Output is correct
31 Correct 58 ms 135060 KB Output is correct
32 Correct 57 ms 135120 KB Output is correct
33 Correct 57 ms 135108 KB Output is correct
34 Correct 58 ms 135100 KB Output is correct
35 Correct 57 ms 135160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 135060 KB Output is correct
2 Correct 59 ms 135056 KB Output is correct
3 Correct 57 ms 135044 KB Output is correct
4 Correct 55 ms 135108 KB Output is correct
5 Correct 57 ms 135108 KB Output is correct
6 Correct 57 ms 135088 KB Output is correct
7 Correct 57 ms 135120 KB Output is correct
8 Correct 57 ms 135124 KB Output is correct
9 Correct 58 ms 135108 KB Output is correct
10 Correct 57 ms 135088 KB Output is correct
11 Correct 58 ms 135036 KB Output is correct
12 Correct 57 ms 135108 KB Output is correct
13 Correct 58 ms 135108 KB Output is correct
14 Correct 59 ms 135112 KB Output is correct
15 Correct 57 ms 135080 KB Output is correct
16 Correct 58 ms 135160 KB Output is correct
17 Correct 56 ms 135108 KB Output is correct
18 Correct 379 ms 135104 KB Output is correct
19 Correct 205 ms 135108 KB Output is correct
20 Correct 111 ms 135116 KB Output is correct
21 Correct 185 ms 135108 KB Output is correct
22 Correct 248 ms 135116 KB Output is correct
23 Correct 101 ms 135096 KB Output is correct
24 Correct 87 ms 135160 KB Output is correct
25 Correct 98 ms 135164 KB Output is correct
26 Correct 65 ms 135140 KB Output is correct
27 Correct 101 ms 135192 KB Output is correct
28 Correct 84 ms 135236 KB Output is correct
29 Correct 107 ms 135236 KB Output is correct
30 Correct 87 ms 135108 KB Output is correct
31 Correct 101 ms 135164 KB Output is correct
32 Correct 75 ms 135108 KB Output is correct
33 Correct 103 ms 135092 KB Output is correct
34 Correct 65 ms 135152 KB Output is correct
35 Correct 102 ms 135116 KB Output is correct
36 Correct 68 ms 135116 KB Output is correct
37 Correct 102 ms 135116 KB Output is correct
38 Correct 73 ms 135168 KB Output is correct
39 Correct 107 ms 135276 KB Output is correct
40 Correct 82 ms 135152 KB Output is correct
41 Correct 479 ms 135172 KB Output is correct
42 Correct 302 ms 135168 KB Output is correct
43 Correct 491 ms 135168 KB Output is correct
44 Correct 292 ms 135236 KB Output is correct
45 Correct 459 ms 135100 KB Output is correct
46 Correct 334 ms 135168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 135060 KB Output is correct
2 Correct 59 ms 135056 KB Output is correct
3 Correct 57 ms 135044 KB Output is correct
4 Correct 55 ms 135108 KB Output is correct
5 Correct 57 ms 135108 KB Output is correct
6 Correct 57 ms 135088 KB Output is correct
7 Correct 57 ms 135120 KB Output is correct
8 Correct 57 ms 135124 KB Output is correct
9 Correct 58 ms 135108 KB Output is correct
10 Correct 57 ms 135088 KB Output is correct
11 Correct 58 ms 135036 KB Output is correct
12 Correct 57 ms 135108 KB Output is correct
13 Correct 58 ms 135108 KB Output is correct
14 Correct 59 ms 135112 KB Output is correct
15 Correct 57 ms 135080 KB Output is correct
16 Correct 58 ms 135160 KB Output is correct
17 Correct 56 ms 135108 KB Output is correct
18 Correct 58 ms 135104 KB Output is correct
19 Correct 61 ms 135076 KB Output is correct
20 Correct 59 ms 135108 KB Output is correct
21 Correct 59 ms 135140 KB Output is correct
22 Correct 55 ms 135116 KB Output is correct
23 Correct 57 ms 135108 KB Output is correct
24 Correct 57 ms 135112 KB Output is correct
25 Correct 58 ms 135108 KB Output is correct
26 Correct 57 ms 135112 KB Output is correct
27 Correct 58 ms 135140 KB Output is correct
28 Correct 59 ms 135040 KB Output is correct
29 Correct 57 ms 135144 KB Output is correct
30 Correct 56 ms 135080 KB Output is correct
31 Correct 58 ms 135060 KB Output is correct
32 Correct 57 ms 135120 KB Output is correct
33 Correct 57 ms 135108 KB Output is correct
34 Correct 58 ms 135100 KB Output is correct
35 Correct 57 ms 135160 KB Output is correct
36 Correct 379 ms 135104 KB Output is correct
37 Correct 205 ms 135108 KB Output is correct
38 Correct 111 ms 135116 KB Output is correct
39 Correct 185 ms 135108 KB Output is correct
40 Correct 248 ms 135116 KB Output is correct
41 Correct 101 ms 135096 KB Output is correct
42 Correct 87 ms 135160 KB Output is correct
43 Correct 98 ms 135164 KB Output is correct
44 Correct 65 ms 135140 KB Output is correct
45 Correct 101 ms 135192 KB Output is correct
46 Correct 84 ms 135236 KB Output is correct
47 Correct 107 ms 135236 KB Output is correct
48 Correct 87 ms 135108 KB Output is correct
49 Correct 101 ms 135164 KB Output is correct
50 Correct 75 ms 135108 KB Output is correct
51 Correct 103 ms 135092 KB Output is correct
52 Correct 65 ms 135152 KB Output is correct
53 Correct 102 ms 135116 KB Output is correct
54 Correct 68 ms 135116 KB Output is correct
55 Correct 102 ms 135116 KB Output is correct
56 Correct 73 ms 135168 KB Output is correct
57 Correct 107 ms 135276 KB Output is correct
58 Correct 82 ms 135152 KB Output is correct
59 Correct 479 ms 135172 KB Output is correct
60 Correct 302 ms 135168 KB Output is correct
61 Correct 491 ms 135168 KB Output is correct
62 Correct 292 ms 135236 KB Output is correct
63 Correct 459 ms 135100 KB Output is correct
64 Correct 334 ms 135168 KB Output is correct
65 Correct 416 ms 135148 KB Output is correct
66 Correct 417 ms 135168 KB Output is correct
67 Correct 353 ms 135168 KB Output is correct
68 Correct 327 ms 135236 KB Output is correct
69 Correct 443 ms 135244 KB Output is correct
70 Correct 381 ms 135168 KB Output is correct
71 Correct 397 ms 135176 KB Output is correct
72 Correct 424 ms 135168 KB Output is correct
73 Correct 365 ms 135236 KB Output is correct
74 Correct 357 ms 135220 KB Output is correct
75 Correct 385 ms 135108 KB Output is correct
76 Correct 414 ms 135108 KB Output is correct
77 Correct 461 ms 135236 KB Output is correct
78 Correct 325 ms 135108 KB Output is correct
79 Correct 337 ms 135148 KB Output is correct
80 Correct 451 ms 135236 KB Output is correct
81 Correct 353 ms 135168 KB Output is correct
82 Correct 377 ms 135180 KB Output is correct
83 Correct 434 ms 135108 KB Output is correct
84 Correct 399 ms 135172 KB Output is correct
85 Correct 453 ms 135236 KB Output is correct
86 Correct 427 ms 135176 KB Output is correct
87 Correct 386 ms 135168 KB Output is correct
88 Correct 485 ms 135172 KB Output is correct
89 Correct 480 ms 135176 KB Output is correct
90 Correct 412 ms 135236 KB Output is correct
91 Correct 509 ms 135172 KB Output is correct
92 Correct 545 ms 135236 KB Output is correct
93 Correct 480 ms 135172 KB Output is correct