Submission #290545

# Submission time Handle Problem Language Result Execution time Memory
290545 2020-09-04T01:35:16 Z eggag32 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
1566 ms 130936 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int mxN = 205;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int n, L;
ll dp[mxN][mxN][mxN][2];

int solve(vector<pi> x){
	rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) rep(l, 2) dp[i][j][k][l] = 1e18;
	dp[0][0][0][0] = dp[0][0][0][1] = 0;
	rep(i, n + 1) rep(j, n + 1 - i) rep(k, min(n + 1, i + j + 1)) rep(l, 2) if(dp[i][j][k][l] < 1e18 && (i + j) <= n){
		if(l == 0){
			int nm = 0;
			repn(i1, i + 1, n + 1){
				if((j + i1) <= n){
					ll dist = dp[i][j][k][l] + (j ? x[j - 1].fi : 0) + (L - x[n - i1].fi);
					if(x[n - i1].se >= dist) nm++;
					dp[i1][j][k + nm][l ^ 1] = min(dp[i1][j][k + nm][l ^ 1], dist);
				}
				else break;
			}
		}
		else{
			int nm = 0;
			repn(j1, j + 1, n + 1){
				if((i + j1) <= n){
					ll dist = dp[i][j][k][l] + x[j1 - 1].fi + (i ? (L - x[n - i].fi) : 0);
					if(x[j1 - 1].se >= dist) nm++;
					dp[i][j1][k + nm][l ^ 1] = min(dp[i][j1][k + nm][l ^ 1], dist);
				}
				else break;
			}
		}
	}
	for(int k = n; k >= 0; k--){
		rep(i, n + 1) rep(j, n + 1) rep(l, 2){
			if(dp[i][j][k][l] != 1e18) return k;
		}	
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cin >> n >> L;
	vector<pi> x(n);
	rep(i, n) cin >> x[i].fi;
	rep(i, n) cin >> x[i].se;
	int mx = solve(x);
	cout << mx << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/

Compilation message

ho_t3.cpp: In function 'int solve(std::vector<std::pair<int, int> >)':
ho_t3.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 896 KB Output is correct
17 Correct 1 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 896 KB Output is correct
17 Correct 1 ms 896 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 768 KB Output is correct
20 Correct 1 ms 896 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 1 ms 1152 KB Output is correct
24 Correct 1 ms 1024 KB Output is correct
25 Correct 1 ms 1152 KB Output is correct
26 Correct 1 ms 1152 KB Output is correct
27 Correct 1 ms 640 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1280 KB Output is correct
31 Correct 1 ms 1152 KB Output is correct
32 Correct 1 ms 1024 KB Output is correct
33 Correct 1 ms 1152 KB Output is correct
34 Correct 1 ms 1152 KB Output is correct
35 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 896 KB Output is correct
17 Correct 1 ms 896 KB Output is correct
18 Correct 784 ms 105052 KB Output is correct
19 Correct 308 ms 63864 KB Output is correct
20 Correct 78 ms 34048 KB Output is correct
21 Correct 247 ms 60160 KB Output is correct
22 Correct 461 ms 78072 KB Output is correct
23 Correct 72 ms 28928 KB Output is correct
24 Correct 33 ms 22656 KB Output is correct
25 Correct 64 ms 28416 KB Output is correct
26 Correct 12 ms 10880 KB Output is correct
27 Correct 75 ms 29568 KB Output is correct
28 Correct 27 ms 21120 KB Output is correct
29 Correct 75 ms 30328 KB Output is correct
30 Correct 34 ms 23808 KB Output is correct
31 Correct 69 ms 28416 KB Output is correct
32 Correct 23 ms 14976 KB Output is correct
33 Correct 64 ms 28416 KB Output is correct
34 Correct 10 ms 10240 KB Output is correct
35 Correct 37 ms 27776 KB Output is correct
36 Correct 14 ms 13184 KB Output is correct
37 Correct 42 ms 29568 KB Output is correct
38 Correct 23 ms 16256 KB Output is correct
39 Correct 45 ms 30848 KB Output is correct
40 Correct 21 ms 18176 KB Output is correct
41 Correct 1205 ms 129656 KB Output is correct
42 Correct 113 ms 87292 KB Output is correct
43 Correct 1217 ms 129656 KB Output is correct
44 Correct 120 ms 86136 KB Output is correct
45 Correct 1226 ms 129556 KB Output is correct
46 Correct 116 ms 87288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 896 KB Output is correct
17 Correct 1 ms 896 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 768 KB Output is correct
20 Correct 1 ms 896 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 1 ms 1152 KB Output is correct
24 Correct 1 ms 1024 KB Output is correct
25 Correct 1 ms 1152 KB Output is correct
26 Correct 1 ms 1152 KB Output is correct
27 Correct 1 ms 640 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1280 KB Output is correct
31 Correct 1 ms 1152 KB Output is correct
32 Correct 1 ms 1024 KB Output is correct
33 Correct 1 ms 1152 KB Output is correct
34 Correct 1 ms 1152 KB Output is correct
35 Correct 1 ms 1152 KB Output is correct
36 Correct 784 ms 105052 KB Output is correct
37 Correct 308 ms 63864 KB Output is correct
38 Correct 78 ms 34048 KB Output is correct
39 Correct 247 ms 60160 KB Output is correct
40 Correct 461 ms 78072 KB Output is correct
41 Correct 72 ms 28928 KB Output is correct
42 Correct 33 ms 22656 KB Output is correct
43 Correct 64 ms 28416 KB Output is correct
44 Correct 12 ms 10880 KB Output is correct
45 Correct 75 ms 29568 KB Output is correct
46 Correct 27 ms 21120 KB Output is correct
47 Correct 75 ms 30328 KB Output is correct
48 Correct 34 ms 23808 KB Output is correct
49 Correct 69 ms 28416 KB Output is correct
50 Correct 23 ms 14976 KB Output is correct
51 Correct 64 ms 28416 KB Output is correct
52 Correct 10 ms 10240 KB Output is correct
53 Correct 37 ms 27776 KB Output is correct
54 Correct 14 ms 13184 KB Output is correct
55 Correct 42 ms 29568 KB Output is correct
56 Correct 23 ms 16256 KB Output is correct
57 Correct 45 ms 30848 KB Output is correct
58 Correct 21 ms 18176 KB Output is correct
59 Correct 1205 ms 129656 KB Output is correct
60 Correct 113 ms 87292 KB Output is correct
61 Correct 1217 ms 129656 KB Output is correct
62 Correct 120 ms 86136 KB Output is correct
63 Correct 1226 ms 129556 KB Output is correct
64 Correct 116 ms 87288 KB Output is correct
65 Correct 1008 ms 117112 KB Output is correct
66 Correct 821 ms 107512 KB Output is correct
67 Correct 748 ms 102904 KB Output is correct
68 Correct 605 ms 94840 KB Output is correct
69 Correct 985 ms 115832 KB Output is correct
70 Correct 943 ms 110948 KB Output is correct
71 Correct 856 ms 112216 KB Output is correct
72 Correct 1034 ms 113400 KB Output is correct
73 Correct 483 ms 105080 KB Output is correct
74 Correct 735 ms 98208 KB Output is correct
75 Correct 797 ms 108664 KB Output is correct
76 Correct 1229 ms 124536 KB Output is correct
77 Correct 1105 ms 124536 KB Output is correct
78 Correct 698 ms 95864 KB Output is correct
79 Correct 815 ms 99324 KB Output is correct
80 Correct 1134 ms 121976 KB Output is correct
81 Correct 727 ms 100472 KB Output is correct
82 Correct 579 ms 106216 KB Output is correct
83 Correct 1160 ms 129560 KB Output is correct
84 Correct 624 ms 110940 KB Output is correct
85 Correct 690 ms 120696 KB Output is correct
86 Correct 736 ms 118220 KB Output is correct
87 Correct 881 ms 108664 KB Output is correct
88 Correct 1521 ms 130856 KB Output is correct
89 Correct 1220 ms 130936 KB Output is correct
90 Correct 155 ms 109688 KB Output is correct
91 Correct 1566 ms 130808 KB Output is correct
92 Correct 1176 ms 130936 KB Output is correct
93 Correct 193 ms 128248 KB Output is correct