Submission #1090378

# Submission time Handle Problem Language Result Execution time Memory
1090378 2024-09-18T09:55:41 Z peacebringer1667 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
114 ms 193872 KB
#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 2e2 + 5;
const ll inf = 1e16;

template <typename T>
   void minimize(T &x,T y){
   	x = min(x,y);
   }

int dist[maxn][maxn],a[maxn],T[maxn];
ll dp[maxn][maxn][maxn][3];

void prepare(int n,int L){
	//prepare dist
	for (int i = 1 ; i <= n ; i++)
		for (int j = 1 ; j <= n ; j++)
		  dist[i][j] = min(abs(a[i] - a[j]),L - a[i] + a[j]);
    
    for (int i = 1 ; i <= n ; i++) 
	   for (int j = 1 ; j <= n ; j++) 
	      for (int k = 0 ; k <= n ; k++)
            dp[i][j][k][0] = dp[i][j][k][1] = inf;
            
    for (int i = 1 ; i <= n ; i++){
      if (min(a[i],L - a[i]) <= T[i]) dp[i][i][1][0] = dp[i][i][1][1] = min(a[i],L - a[i]);
      dp[i][i][0][0] = dp[i][i][0][1] = min(a[i],L - a[i]);
    }
    
}

int solve(int n){
	int res = 0;
    for (int len = 1 ; len < n ; len++)
    	for (int l = 1 ; l <= n ; l++){
    		int r = l + len;
    		if (r > n) r -= n;
    		
    		int lx = (l == n) ? 1 : (l + 1);
    		int rx = (r == 1) ? n : (r - 1);
    		
    		for (int k = 1 ; k <= len + 1; k++){
			    minimize(dp[l][r][k][0],dp[lx][r][k][0] + dist[l][lx]);
			    minimize(dp[l][r][k][0],dp[lx][r][k][1] + dist[l][r]);
				
				minimize(dp[l][r][k][1],dp[l][rx][k][1] + dist[rx][r]);
				minimize(dp[l][r][k][1],dp[l][rx][k][0] + dist[l][r]);
				
				if (dp[lx][r][k - 1][0] + dist[l][lx] <= T[l])
				  minimize(dp[l][r][k][0],dp[lx][r][k - 1][0] + dist[l][lx]);
				if (dp[lx][r][k - 1][1] + dist[l][r] <= T[l])
				  minimize(dp[l][r][k][0],dp[lx][r][k - 1][1] + dist[l][r]);
				
				
				if (dp[l][rx][k - 1][1] + dist[rx][r] <= T[r])
				  minimize(dp[l][r][k][1],dp[l][rx][k - 1][1] + dist[rx][r]);
				if (dp[l][rx][k - 1][0] + dist[l][r] <= T[r])
				  minimize(dp[l][r][k][1],dp[l][rx][k - 1][0] + dist[l][r]);
			}
		}
	
	for (int l = 1 ; l <= n ; l++)
	  for (int r = 1 ; r <= n ;r++)
	    for (int k = 1 ; k <= n ; k++)
	      if (min(dp[l][r][k][0],dp[l][r][k][1]) < inf)
	      	res = max(res,k);
	      
	
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	int n,L;
	cin >> n >> L;
	for (int i = 1 ; i <= n ; i++) cin >> a[i];
	for (int i = 1 ; i <= n ; i++) cin >> T[i];
	
	prepare(n,L);
	
	cout << solve(n);
    
	return 0;
}

Compilation message

ho_t3.cpp: In function 'int solve(int)':
ho_t3.cpp:41:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 |     for (int len = 1 ; len < n ; len++)
      |     ^~~
ho_t3.cpp:69:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   69 |  for (int l = 1 ; l <= n ; l++)
      |  ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 0 ms 860 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 1 ms 1368 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1232 KB Output is correct
26 Correct 0 ms 1228 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 1 ms 1372 KB Output is correct
34 Correct 1 ms 1372 KB Output is correct
35 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 91 ms 155428 KB Output is correct
19 Correct 63 ms 93864 KB Output is correct
20 Correct 28 ms 49756 KB Output is correct
21 Correct 54 ms 88552 KB Output is correct
22 Correct 72 ms 115020 KB Output is correct
23 Correct 22 ms 42332 KB Output is correct
24 Correct 17 ms 32860 KB Output is correct
25 Correct 26 ms 41308 KB Output is correct
26 Correct 7 ms 15708 KB Output is correct
27 Correct 22 ms 43312 KB Output is correct
28 Correct 15 ms 30556 KB Output is correct
29 Correct 28 ms 44004 KB Output is correct
30 Correct 18 ms 34652 KB Output is correct
31 Correct 21 ms 41308 KB Output is correct
32 Correct 13 ms 21592 KB Output is correct
33 Correct 23 ms 41308 KB Output is correct
34 Correct 7 ms 14612 KB Output is correct
35 Correct 20 ms 40540 KB Output is correct
36 Correct 10 ms 19036 KB Output is correct
37 Correct 21 ms 43100 KB Output is correct
38 Correct 11 ms 23388 KB Output is correct
39 Correct 24 ms 45148 KB Output is correct
40 Correct 12 ms 26204 KB Output is correct
41 Correct 109 ms 191868 KB Output is correct
42 Correct 78 ms 128852 KB Output is correct
43 Correct 110 ms 191828 KB Output is correct
44 Correct 77 ms 127416 KB Output is correct
45 Correct 108 ms 191828 KB Output is correct
46 Correct 74 ms 128944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 0 ms 860 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 1 ms 1368 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1232 KB Output is correct
26 Correct 0 ms 1228 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 1 ms 1372 KB Output is correct
34 Correct 1 ms 1372 KB Output is correct
35 Correct 1 ms 1372 KB Output is correct
36 Correct 91 ms 155428 KB Output is correct
37 Correct 63 ms 93864 KB Output is correct
38 Correct 28 ms 49756 KB Output is correct
39 Correct 54 ms 88552 KB Output is correct
40 Correct 72 ms 115020 KB Output is correct
41 Correct 22 ms 42332 KB Output is correct
42 Correct 17 ms 32860 KB Output is correct
43 Correct 26 ms 41308 KB Output is correct
44 Correct 7 ms 15708 KB Output is correct
45 Correct 22 ms 43312 KB Output is correct
46 Correct 15 ms 30556 KB Output is correct
47 Correct 28 ms 44004 KB Output is correct
48 Correct 18 ms 34652 KB Output is correct
49 Correct 21 ms 41308 KB Output is correct
50 Correct 13 ms 21592 KB Output is correct
51 Correct 23 ms 41308 KB Output is correct
52 Correct 7 ms 14612 KB Output is correct
53 Correct 20 ms 40540 KB Output is correct
54 Correct 10 ms 19036 KB Output is correct
55 Correct 21 ms 43100 KB Output is correct
56 Correct 11 ms 23388 KB Output is correct
57 Correct 24 ms 45148 KB Output is correct
58 Correct 12 ms 26204 KB Output is correct
59 Correct 109 ms 191868 KB Output is correct
60 Correct 78 ms 128852 KB Output is correct
61 Correct 110 ms 191828 KB Output is correct
62 Correct 77 ms 127416 KB Output is correct
63 Correct 108 ms 191828 KB Output is correct
64 Correct 74 ms 128944 KB Output is correct
65 Correct 100 ms 173264 KB Output is correct
66 Correct 92 ms 158804 KB Output is correct
67 Correct 84 ms 151976 KB Output is correct
68 Correct 77 ms 140112 KB Output is correct
69 Correct 96 ms 171320 KB Output is correct
70 Correct 106 ms 164232 KB Output is correct
71 Correct 98 ms 166056 KB Output is correct
72 Correct 99 ms 167760 KB Output is correct
73 Correct 89 ms 155476 KB Output is correct
74 Correct 80 ms 145228 KB Output is correct
75 Correct 90 ms 160548 KB Output is correct
76 Correct 101 ms 184320 KB Output is correct
77 Correct 95 ms 184404 KB Output is correct
78 Correct 82 ms 141964 KB Output is correct
79 Correct 78 ms 146772 KB Output is correct
80 Correct 95 ms 180564 KB Output is correct
81 Correct 81 ms 148560 KB Output is correct
82 Correct 83 ms 156996 KB Output is correct
83 Correct 99 ms 191824 KB Output is correct
84 Correct 86 ms 164176 KB Output is correct
85 Correct 92 ms 178768 KB Output is correct
86 Correct 90 ms 174932 KB Output is correct
87 Correct 88 ms 160596 KB Output is correct
88 Correct 102 ms 193872 KB Output is correct
89 Correct 105 ms 193872 KB Output is correct
90 Correct 103 ms 162484 KB Output is correct
91 Correct 114 ms 193728 KB Output is correct
92 Correct 108 ms 193732 KB Output is correct
93 Correct 102 ms 190036 KB Output is correct