답안 #890623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890623 2023-12-21T16:29:38 Z LCJLY Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
118 ms 135436 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;

int n=0;
int len=0;
int pos[205];
int limit[205];
//int memo[205][205][2][205];

//int dp(int l, int r, bool flag, int cur){
	//if(cur>200) return 0;
	//if(l+1>=r) return 0;
	//if(memo[l][r][flag][cur]!=-1) return memo[l][r][flag][cur];
	//int ans=0;
	
	//int dist=cur;
	//if(!flag) dist+=(pos[l+1]-pos[l]);
	//else dist+=(pos[l+1]+k-pos[r]);
	//ans=max(ans,dp(l+1,r,0,dist)+(dist<=limit[l+1]));
	
	//int dist2=cur;
	//if(flag) dist2+=(pos[r]-pos[r-1]);
	//else dist2+=(pos[l]+k-pos[r-1]);
	//ans=max(ans,dp(l,r-1,1,dist2)+(dist2<=limit[r-1]));
	//return memo[l][r][flag][cur]=ans;
//}

void solve(){	
	cin >> n >> len;

	//memset(memo,-1,sizeof(memo));
	for(int x=1;x<=n;x++) cin >> pos[x];
	for(int x=1;x<=n;x++) cin >> limit[x];
	pos[n+1]=len;
	
	//min amount of time to cover (l,r) such that last is a left/right, visiting k stuff
	int dp[n+5][n+5][n+5][2];
	for(int x=0;x<n+5;x++){
		for(int y=0;y<n+5;y++){
			for(int i=0;i<n+5;i++){
				dp[x][y][i][0]=1e15;
				dp[x][y][i][1]=1e15;
			}
		}
	}
	
	dp[0][n+1][0][0]=0;
	dp[0][n+1][0][1]=0;
	
	for(int l=0;l<=n;l++){
		for(int r=n+1;r>l;r--){
			for(int k=0;k<=n;k++){
				//last is left
				int dist=dp[l][r][k][0];
				//visit lft rgt
				int left=pos[l+1]-pos[l];
				int right=pos[l]+len-pos[r-1];
				
				//no take
				dp[l+1][r][k][0]=min(dp[l+1][r][k][0],dist+left);
				dp[l][r-1][k][1]=min(dp[l][r-1][k][1],dist+right);
				
				//take
				if(dist+left<=limit[l+1]){
					dp[l+1][r][k+1][0]=min(dp[l+1][r][k+1][0],dist+left);
				}
				if(dist+right<=limit[r-1]){
					dp[l][r-1][k+1][1]=min(dp[l][r-1][k+1][1],dist+right);
				}
				

				//last is right
				dist=dp[l][r][k][1];
				left=pos[l+1]+len-pos[r];
				right=pos[r]-pos[r-1];
				
				dp[l+1][r][k][0]=min(dp[l+1][r][k][0],dist+left);
				dp[l][r-1][k][1]=min(dp[l][r-1][k][1],dist+right);
				
				if(dist+left<=limit[l+1]){
					dp[l+1][r][k+1][0]=min(dp[l+1][r][k+1][0],dist+left);
				}
				if(dist+right<=limit[r-1]){
					dp[l][r-1][k+1][1]=min(dp[l][r-1][k+1][1],dist+right);
				}
				
				//show3(l,l,r,r,k,k);
				//show2(left,dp[l][r][k][0],right,dp[l][r][k][1]);
			}
		}
	}
	
	int best=0;
	for(int l=0;l<=n;l++){
		for(int r=l+1;r<=n+1;r++){
			for(int k=0;k<=n;k++){
				if(dp[l][r][k][0]<1e15) best=max(best,k);
				if(dp[l][r][k][1]<1e15) best=max(best,k);
			}
		}
	}
	
	cout << best;
}	

int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 464 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 464 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 456 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 388 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 464 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 70 ms 97864 KB Output is correct
19 Correct 37 ms 46984 KB Output is correct
20 Correct 14 ms 19036 KB Output is correct
21 Correct 36 ms 43268 KB Output is correct
22 Correct 45 ms 63312 KB Output is correct
23 Correct 11 ms 14936 KB Output is correct
24 Correct 7 ms 10588 KB Output is correct
25 Correct 11 ms 14740 KB Output is correct
26 Correct 3 ms 3984 KB Output is correct
27 Correct 11 ms 15452 KB Output is correct
28 Correct 6 ms 9564 KB Output is correct
29 Correct 12 ms 15960 KB Output is correct
30 Correct 8 ms 11356 KB Output is correct
31 Correct 10 ms 14684 KB Output is correct
32 Correct 4 ms 5980 KB Output is correct
33 Correct 13 ms 14684 KB Output is correct
34 Correct 3 ms 3420 KB Output is correct
35 Correct 12 ms 14172 KB Output is correct
36 Correct 3 ms 4956 KB Output is correct
37 Correct 10 ms 15640 KB Output is correct
38 Correct 5 ms 6748 KB Output is correct
39 Correct 12 ms 16476 KB Output is correct
40 Correct 5 ms 7772 KB Output is correct
41 Correct 98 ms 133108 KB Output is correct
42 Correct 53 ms 74580 KB Output is correct
43 Correct 96 ms 133344 KB Output is correct
44 Correct 56 ms 73196 KB Output is correct
45 Correct 96 ms 133276 KB Output is correct
46 Correct 56 ms 74740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 464 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 456 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 388 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 456 KB Output is correct
36 Correct 70 ms 97864 KB Output is correct
37 Correct 37 ms 46984 KB Output is correct
38 Correct 14 ms 19036 KB Output is correct
39 Correct 36 ms 43268 KB Output is correct
40 Correct 45 ms 63312 KB Output is correct
41 Correct 11 ms 14936 KB Output is correct
42 Correct 7 ms 10588 KB Output is correct
43 Correct 11 ms 14740 KB Output is correct
44 Correct 3 ms 3984 KB Output is correct
45 Correct 11 ms 15452 KB Output is correct
46 Correct 6 ms 9564 KB Output is correct
47 Correct 12 ms 15960 KB Output is correct
48 Correct 8 ms 11356 KB Output is correct
49 Correct 10 ms 14684 KB Output is correct
50 Correct 4 ms 5980 KB Output is correct
51 Correct 13 ms 14684 KB Output is correct
52 Correct 3 ms 3420 KB Output is correct
53 Correct 12 ms 14172 KB Output is correct
54 Correct 3 ms 4956 KB Output is correct
55 Correct 10 ms 15640 KB Output is correct
56 Correct 5 ms 6748 KB Output is correct
57 Correct 12 ms 16476 KB Output is correct
58 Correct 5 ms 7772 KB Output is correct
59 Correct 98 ms 133108 KB Output is correct
60 Correct 53 ms 74580 KB Output is correct
61 Correct 96 ms 133344 KB Output is correct
62 Correct 56 ms 73196 KB Output is correct
63 Correct 96 ms 133276 KB Output is correct
64 Correct 56 ms 74740 KB Output is correct
65 Correct 81 ms 114512 KB Output is correct
66 Correct 77 ms 101172 KB Output is correct
67 Correct 69 ms 94816 KB Output is correct
68 Correct 61 ms 84340 KB Output is correct
69 Correct 80 ms 112888 KB Output is correct
70 Correct 77 ms 106064 KB Output is correct
71 Correct 82 ms 107672 KB Output is correct
72 Correct 80 ms 109284 KB Output is correct
73 Correct 76 ms 97960 KB Output is correct
74 Correct 65 ms 88724 KB Output is correct
75 Correct 74 ms 102736 KB Output is correct
76 Correct 92 ms 125520 KB Output is correct
77 Correct 90 ms 125448 KB Output is correct
78 Correct 65 ms 85992 KB Output is correct
79 Correct 65 ms 90196 KB Output is correct
80 Correct 93 ms 121936 KB Output is correct
81 Correct 64 ms 91532 KB Output is correct
82 Correct 80 ms 99568 KB Output is correct
83 Correct 95 ms 133344 KB Output is correct
84 Correct 77 ms 105968 KB Output is correct
85 Correct 83 ms 120128 KB Output is correct
86 Correct 82 ms 116268 KB Output is correct
87 Correct 73 ms 102708 KB Output is correct
88 Correct 105 ms 135248 KB Output is correct
89 Correct 118 ms 135084 KB Output is correct
90 Correct 73 ms 104264 KB Output is correct
91 Correct 107 ms 135436 KB Output is correct
92 Correct 97 ms 135312 KB Output is correct
93 Correct 92 ms 131408 KB Output is correct