답안 #211111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211111 2020-03-19T08:48:03 Z kshitij_sodani Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
166 ms 130172 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
llo t[201];
llo it[201];
llo n,l;
llo ma=0;

llo dp[201][201][205][2];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>l;
	memset(dp,-1,sizeof(dp));
 	for(int i=0;i<201;i++){
 		for(int j=0;j<201;j++){
 			for(int k=0;k<205;k++){
 				dp[i][j][k][0]=-1;
 				dp[i][j][k][1]=-1;
 			}
 		}
 	}
	for(llo i=0;i<n;i++){
		cin>>it[i];
	}
	for(llo i=0;i<n;i++){
		cin>>t[i];
	}
 
	for(llo i=0;i<n;i++){
		llo dis=min(it[i],l-it[i]);
		llo val=0;
		if(dis<=t[i]){
			val=1;
		}
		dp[i][i][val][0]=dis;
		dp[i][i][val][1]=dis;
	}
 
	for(llo ii=1;ii<n;ii++){
		for(llo j=0;j<n;j++){
			llo i=(j+ii)%n;
			for(llo k=0;k<n+1;k++){
				if(dp[j][(i-1+n)%n][k][1]>-1){
					llo tt=dp[j][(i-1+n)%n][k][1]+min(abs(it[i]-it[(i-1+n)%n]),l-abs(it[i]-it[(i-1+n)%n]));
					if(tt<=t[i]){
						if(dp[j][i][k+1][1]==-1){
							dp[j][i][k+1][1]=tt;
						}
						dp[j][i][k+1][1]=min(dp[j][i][k+1][1],tt);
					}
					if(dp[j][i][k][1]==-1){
						dp[j][i][k][1]=tt;
					}
					dp[j][i][k][1]=min(dp[j][i][k][1],tt);
				}	
				if(dp[j][(i-1+n)%n][k][0]>-1){
					llo tt=dp[j][(i-1+n)%n][k][0]+min(abs(it[i]-it[j]),l-abs(it[i]-it[j]));
					if(tt<=t[i]){
						if(dp[j][i][k+1][1]==-1){
							dp[j][i][k+1][1]=tt;
						}
						dp[j][i][k+1][1]=min(dp[j][i][k+1][1],tt);
					}
					if(dp[j][i][k][1]==-1){
						dp[j][i][k][1]=tt;
					}
					dp[j][i][k][1]=min(dp[j][i][k][1],tt);
				}	
				
				
				if(dp[(j+1)%n][i][k][0]>-1){
					llo tt=dp[(j+1)%n][i][k][0]+min(abs(it[j]-it[(j+1)%n]),l-abs(it[j]-it[(j+1)%n]));
					if(tt<=t[j]){
						if(dp[j][i][k+1][0]==-1){
							dp[j][i][k+1][0]=tt;
						}
						dp[j][i][k+1][0]=min(dp[j][i][k+1][0],tt);
					}
					if(dp[j][i][k][0]==-1){
						dp[j][i][k][0]=tt;
					}
					dp[j][i][k][0]=min(dp[j][i][k][0],tt);
				}	
				if(dp[(j+1)%n][i][k][1]>-1){
					llo tt=dp[(j+1)%n][i][k][1]+min(abs(it[j]-it[i]),l-abs(it[j]-it[i]));
					if(tt<=t[j]){
						if(dp[j][i][k+1][0]==-1){
							dp[j][i][k+1][0]=tt;
						}
						dp[j][i][k+1][0]=min(dp[j][i][k+1][0],tt);
					}
					if(dp[j][i][k][0]==-1){
						dp[j][i][k][0]=tt;
					}
					dp[j][i][k][0]=min(dp[j][i][k][0],tt);
				}	
			}
		}
	}
	llo ans=0;
	for(llo i=0;i<n;i++){
		for(llo j=0;j<n;j++){
			for(llo k=0;k<n+1;k++){
				if(dp[i][j][k][0]!=-1){
					ans=max(ans,k);
				}
				if(dp[i][j][k][1]!=-1){
					ans=max(ans,k);
				}

			}
		}
	}
	cout<<ans<<endl;
 
 
	return 0;
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 130040 KB Output is correct
2 Correct 82 ms 129928 KB Output is correct
3 Correct 82 ms 130040 KB Output is correct
4 Correct 82 ms 130040 KB Output is correct
5 Correct 83 ms 130040 KB Output is correct
6 Correct 81 ms 130040 KB Output is correct
7 Correct 83 ms 130044 KB Output is correct
8 Correct 81 ms 130120 KB Output is correct
9 Correct 80 ms 129928 KB Output is correct
10 Correct 82 ms 130040 KB Output is correct
11 Correct 81 ms 130168 KB Output is correct
12 Correct 83 ms 130040 KB Output is correct
13 Correct 84 ms 130040 KB Output is correct
14 Correct 81 ms 130040 KB Output is correct
15 Correct 82 ms 130040 KB Output is correct
16 Correct 82 ms 130168 KB Output is correct
17 Correct 80 ms 130016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 130040 KB Output is correct
2 Correct 82 ms 129928 KB Output is correct
3 Correct 82 ms 130040 KB Output is correct
4 Correct 82 ms 130040 KB Output is correct
5 Correct 83 ms 130040 KB Output is correct
6 Correct 81 ms 130040 KB Output is correct
7 Correct 83 ms 130044 KB Output is correct
8 Correct 81 ms 130120 KB Output is correct
9 Correct 80 ms 129928 KB Output is correct
10 Correct 82 ms 130040 KB Output is correct
11 Correct 81 ms 130168 KB Output is correct
12 Correct 83 ms 130040 KB Output is correct
13 Correct 84 ms 130040 KB Output is correct
14 Correct 81 ms 130040 KB Output is correct
15 Correct 82 ms 130040 KB Output is correct
16 Correct 82 ms 130168 KB Output is correct
17 Correct 80 ms 130016 KB Output is correct
18 Correct 80 ms 130040 KB Output is correct
19 Correct 82 ms 130040 KB Output is correct
20 Correct 82 ms 130040 KB Output is correct
21 Correct 82 ms 130040 KB Output is correct
22 Correct 81 ms 130040 KB Output is correct
23 Correct 83 ms 130040 KB Output is correct
24 Correct 82 ms 130040 KB Output is correct
25 Correct 88 ms 130168 KB Output is correct
26 Correct 82 ms 130040 KB Output is correct
27 Correct 81 ms 130040 KB Output is correct
28 Correct 82 ms 130040 KB Output is correct
29 Correct 80 ms 130040 KB Output is correct
30 Correct 83 ms 130052 KB Output is correct
31 Correct 83 ms 130040 KB Output is correct
32 Correct 83 ms 130044 KB Output is correct
33 Correct 83 ms 130040 KB Output is correct
34 Correct 83 ms 130040 KB Output is correct
35 Correct 81 ms 130040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 130040 KB Output is correct
2 Correct 82 ms 129928 KB Output is correct
3 Correct 82 ms 130040 KB Output is correct
4 Correct 82 ms 130040 KB Output is correct
5 Correct 83 ms 130040 KB Output is correct
6 Correct 81 ms 130040 KB Output is correct
7 Correct 83 ms 130044 KB Output is correct
8 Correct 81 ms 130120 KB Output is correct
9 Correct 80 ms 129928 KB Output is correct
10 Correct 82 ms 130040 KB Output is correct
11 Correct 81 ms 130168 KB Output is correct
12 Correct 83 ms 130040 KB Output is correct
13 Correct 84 ms 130040 KB Output is correct
14 Correct 81 ms 130040 KB Output is correct
15 Correct 82 ms 130040 KB Output is correct
16 Correct 82 ms 130168 KB Output is correct
17 Correct 80 ms 130016 KB Output is correct
18 Correct 129 ms 130040 KB Output is correct
19 Correct 108 ms 130040 KB Output is correct
20 Correct 101 ms 130040 KB Output is correct
21 Correct 106 ms 130040 KB Output is correct
22 Correct 121 ms 130040 KB Output is correct
23 Correct 95 ms 130016 KB Output is correct
24 Correct 87 ms 130040 KB Output is correct
25 Correct 95 ms 130040 KB Output is correct
26 Correct 83 ms 130012 KB Output is correct
27 Correct 97 ms 130040 KB Output is correct
28 Correct 86 ms 130040 KB Output is correct
29 Correct 96 ms 130040 KB Output is correct
30 Correct 90 ms 130168 KB Output is correct
31 Correct 93 ms 130040 KB Output is correct
32 Correct 88 ms 130040 KB Output is correct
33 Correct 93 ms 130040 KB Output is correct
34 Correct 83 ms 130040 KB Output is correct
35 Correct 89 ms 130040 KB Output is correct
36 Correct 84 ms 130040 KB Output is correct
37 Correct 92 ms 130040 KB Output is correct
38 Correct 86 ms 130040 KB Output is correct
39 Correct 92 ms 130040 KB Output is correct
40 Correct 95 ms 130040 KB Output is correct
41 Correct 150 ms 130040 KB Output is correct
42 Correct 108 ms 130108 KB Output is correct
43 Correct 162 ms 130168 KB Output is correct
44 Correct 108 ms 130040 KB Output is correct
45 Correct 156 ms 130168 KB Output is correct
46 Correct 110 ms 130140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 130040 KB Output is correct
2 Correct 82 ms 129928 KB Output is correct
3 Correct 82 ms 130040 KB Output is correct
4 Correct 82 ms 130040 KB Output is correct
5 Correct 83 ms 130040 KB Output is correct
6 Correct 81 ms 130040 KB Output is correct
7 Correct 83 ms 130044 KB Output is correct
8 Correct 81 ms 130120 KB Output is correct
9 Correct 80 ms 129928 KB Output is correct
10 Correct 82 ms 130040 KB Output is correct
11 Correct 81 ms 130168 KB Output is correct
12 Correct 83 ms 130040 KB Output is correct
13 Correct 84 ms 130040 KB Output is correct
14 Correct 81 ms 130040 KB Output is correct
15 Correct 82 ms 130040 KB Output is correct
16 Correct 82 ms 130168 KB Output is correct
17 Correct 80 ms 130016 KB Output is correct
18 Correct 80 ms 130040 KB Output is correct
19 Correct 82 ms 130040 KB Output is correct
20 Correct 82 ms 130040 KB Output is correct
21 Correct 82 ms 130040 KB Output is correct
22 Correct 81 ms 130040 KB Output is correct
23 Correct 83 ms 130040 KB Output is correct
24 Correct 82 ms 130040 KB Output is correct
25 Correct 88 ms 130168 KB Output is correct
26 Correct 82 ms 130040 KB Output is correct
27 Correct 81 ms 130040 KB Output is correct
28 Correct 82 ms 130040 KB Output is correct
29 Correct 80 ms 130040 KB Output is correct
30 Correct 83 ms 130052 KB Output is correct
31 Correct 83 ms 130040 KB Output is correct
32 Correct 83 ms 130044 KB Output is correct
33 Correct 83 ms 130040 KB Output is correct
34 Correct 83 ms 130040 KB Output is correct
35 Correct 81 ms 130040 KB Output is correct
36 Correct 129 ms 130040 KB Output is correct
37 Correct 108 ms 130040 KB Output is correct
38 Correct 101 ms 130040 KB Output is correct
39 Correct 106 ms 130040 KB Output is correct
40 Correct 121 ms 130040 KB Output is correct
41 Correct 95 ms 130016 KB Output is correct
42 Correct 87 ms 130040 KB Output is correct
43 Correct 95 ms 130040 KB Output is correct
44 Correct 83 ms 130012 KB Output is correct
45 Correct 97 ms 130040 KB Output is correct
46 Correct 86 ms 130040 KB Output is correct
47 Correct 96 ms 130040 KB Output is correct
48 Correct 90 ms 130168 KB Output is correct
49 Correct 93 ms 130040 KB Output is correct
50 Correct 88 ms 130040 KB Output is correct
51 Correct 93 ms 130040 KB Output is correct
52 Correct 83 ms 130040 KB Output is correct
53 Correct 89 ms 130040 KB Output is correct
54 Correct 84 ms 130040 KB Output is correct
55 Correct 92 ms 130040 KB Output is correct
56 Correct 86 ms 130040 KB Output is correct
57 Correct 92 ms 130040 KB Output is correct
58 Correct 95 ms 130040 KB Output is correct
59 Correct 150 ms 130040 KB Output is correct
60 Correct 108 ms 130108 KB Output is correct
61 Correct 162 ms 130168 KB Output is correct
62 Correct 108 ms 130040 KB Output is correct
63 Correct 156 ms 130168 KB Output is correct
64 Correct 110 ms 130140 KB Output is correct
65 Correct 145 ms 130040 KB Output is correct
66 Correct 134 ms 130160 KB Output is correct
67 Correct 129 ms 130040 KB Output is correct
68 Correct 139 ms 130040 KB Output is correct
69 Correct 140 ms 130040 KB Output is correct
70 Correct 153 ms 130168 KB Output is correct
71 Correct 131 ms 130044 KB Output is correct
72 Correct 154 ms 130040 KB Output is correct
73 Correct 134 ms 130040 KB Output is correct
74 Correct 140 ms 130040 KB Output is correct
75 Correct 127 ms 130040 KB Output is correct
76 Correct 154 ms 130040 KB Output is correct
77 Correct 138 ms 130040 KB Output is correct
78 Correct 135 ms 130052 KB Output is correct
79 Correct 125 ms 130040 KB Output is correct
80 Correct 152 ms 130168 KB Output is correct
81 Correct 126 ms 130040 KB Output is correct
82 Correct 125 ms 130040 KB Output is correct
83 Correct 146 ms 130168 KB Output is correct
84 Correct 127 ms 130124 KB Output is correct
85 Correct 137 ms 130040 KB Output is correct
86 Correct 131 ms 130040 KB Output is correct
87 Correct 138 ms 130040 KB Output is correct
88 Correct 166 ms 130040 KB Output is correct
89 Correct 156 ms 130144 KB Output is correct
90 Correct 116 ms 130172 KB Output is correct
91 Correct 160 ms 130040 KB Output is correct
92 Correct 153 ms 130084 KB Output is correct
93 Correct 123 ms 130040 KB Output is correct