Submission #257146

# Submission time Handle Problem Language Result Execution time Memory
257146 2020-08-03T16:22:06 Z jainbot27 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
465 ms 127632 KB
//Author: jainbot27
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()


const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;


str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
	str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
	bool fst = 1; str res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += ts(x);
	}
	res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
	return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << ts(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }


#ifdef D 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int mxN = 201;
int n; ll L, x[mxN], t[mxN], dp[mxN][mxN][mxN][2];

ll dist(ll a, ll b){
	return min(abs(x[b] - x[a]), L - abs(x[b] - x[a]));
}
ll solve(int l, int r, int side, int cnt){
	if(cnt == 0){
		return 1e18;
	}
	if(l > r){
		return -1e18;
	}
	if(dp[l][r][cnt][side]!=-1)
		return dp[l][r][cnt][side];
	int nex = l-1;
	if(side == 1)
		nex = r + 1;
	ll ret = -1e18;
	ret= max(ret, solve(l + 1, r, 0, cnt) - dist(l, nex));
	ret = max(ret, min(t[l], solve(l + 1, r, 0, cnt  - 1)) - dist(l, nex));
	ret = max(ret, solve(l, r - 1, 1, cnt) - dist(r, nex));
	ret = max(ret, min(t[r], solve(l, r-1, 1, cnt - 1)) - dist(r, nex));
	return dp[l][r][cnt][side] = ret;
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	memset(dp, -1, sizeof(dp));
	cin >> n >> L;
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}	
	for(int i = 0; i < n; i++){
		cin >> t[i];
	}	
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		if(solve(0, n-1, 1, i) >= 0)
			ans = i;
	}
	cout << ans << nl;
}
# Verdict Execution time Memory Grader output
1 Correct 73 ms 127480 KB Output is correct
2 Correct 73 ms 127480 KB Output is correct
3 Correct 66 ms 127480 KB Output is correct
4 Correct 75 ms 127480 KB Output is correct
5 Correct 71 ms 127480 KB Output is correct
6 Correct 66 ms 127480 KB Output is correct
7 Correct 74 ms 127480 KB Output is correct
8 Correct 70 ms 127480 KB Output is correct
9 Correct 66 ms 127484 KB Output is correct
10 Correct 66 ms 127480 KB Output is correct
11 Correct 67 ms 127480 KB Output is correct
12 Correct 65 ms 127608 KB Output is correct
13 Correct 67 ms 127480 KB Output is correct
14 Correct 65 ms 127484 KB Output is correct
15 Correct 66 ms 127480 KB Output is correct
16 Correct 66 ms 127492 KB Output is correct
17 Correct 68 ms 127480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 127480 KB Output is correct
2 Correct 73 ms 127480 KB Output is correct
3 Correct 66 ms 127480 KB Output is correct
4 Correct 75 ms 127480 KB Output is correct
5 Correct 71 ms 127480 KB Output is correct
6 Correct 66 ms 127480 KB Output is correct
7 Correct 74 ms 127480 KB Output is correct
8 Correct 70 ms 127480 KB Output is correct
9 Correct 66 ms 127484 KB Output is correct
10 Correct 66 ms 127480 KB Output is correct
11 Correct 67 ms 127480 KB Output is correct
12 Correct 65 ms 127608 KB Output is correct
13 Correct 67 ms 127480 KB Output is correct
14 Correct 65 ms 127484 KB Output is correct
15 Correct 66 ms 127480 KB Output is correct
16 Correct 66 ms 127492 KB Output is correct
17 Correct 68 ms 127480 KB Output is correct
18 Correct 65 ms 127484 KB Output is correct
19 Correct 67 ms 127484 KB Output is correct
20 Correct 67 ms 127480 KB Output is correct
21 Correct 66 ms 127608 KB Output is correct
22 Correct 72 ms 127480 KB Output is correct
23 Correct 66 ms 127480 KB Output is correct
24 Correct 65 ms 127480 KB Output is correct
25 Correct 65 ms 127480 KB Output is correct
26 Correct 70 ms 127440 KB Output is correct
27 Correct 67 ms 127480 KB Output is correct
28 Correct 67 ms 127632 KB Output is correct
29 Correct 65 ms 127480 KB Output is correct
30 Correct 66 ms 127480 KB Output is correct
31 Correct 67 ms 127480 KB Output is correct
32 Correct 68 ms 127484 KB Output is correct
33 Correct 65 ms 127480 KB Output is correct
34 Correct 66 ms 127480 KB Output is correct
35 Correct 97 ms 127480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 127480 KB Output is correct
2 Correct 73 ms 127480 KB Output is correct
3 Correct 66 ms 127480 KB Output is correct
4 Correct 75 ms 127480 KB Output is correct
5 Correct 71 ms 127480 KB Output is correct
6 Correct 66 ms 127480 KB Output is correct
7 Correct 74 ms 127480 KB Output is correct
8 Correct 70 ms 127480 KB Output is correct
9 Correct 66 ms 127484 KB Output is correct
10 Correct 66 ms 127480 KB Output is correct
11 Correct 67 ms 127480 KB Output is correct
12 Correct 65 ms 127608 KB Output is correct
13 Correct 67 ms 127480 KB Output is correct
14 Correct 65 ms 127484 KB Output is correct
15 Correct 66 ms 127480 KB Output is correct
16 Correct 66 ms 127492 KB Output is correct
17 Correct 68 ms 127480 KB Output is correct
18 Correct 264 ms 127492 KB Output is correct
19 Correct 155 ms 127516 KB Output is correct
20 Correct 97 ms 127480 KB Output is correct
21 Correct 142 ms 127532 KB Output is correct
22 Correct 199 ms 127480 KB Output is correct
23 Correct 99 ms 127480 KB Output is correct
24 Correct 91 ms 127480 KB Output is correct
25 Correct 93 ms 127480 KB Output is correct
26 Correct 71 ms 127608 KB Output is correct
27 Correct 98 ms 127524 KB Output is correct
28 Correct 89 ms 127480 KB Output is correct
29 Correct 101 ms 127480 KB Output is correct
30 Correct 92 ms 127480 KB Output is correct
31 Correct 90 ms 127480 KB Output is correct
32 Correct 82 ms 127480 KB Output is correct
33 Correct 88 ms 127480 KB Output is correct
34 Correct 71 ms 127524 KB Output is correct
35 Correct 95 ms 127608 KB Output is correct
36 Correct 73 ms 127480 KB Output is correct
37 Correct 95 ms 127532 KB Output is correct
38 Correct 77 ms 127524 KB Output is correct
39 Correct 98 ms 127480 KB Output is correct
40 Correct 77 ms 127608 KB Output is correct
41 Correct 324 ms 127536 KB Output is correct
42 Correct 207 ms 127484 KB Output is correct
43 Correct 322 ms 127608 KB Output is correct
44 Correct 192 ms 127480 KB Output is correct
45 Correct 319 ms 127600 KB Output is correct
46 Correct 200 ms 127480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 127480 KB Output is correct
2 Correct 73 ms 127480 KB Output is correct
3 Correct 66 ms 127480 KB Output is correct
4 Correct 75 ms 127480 KB Output is correct
5 Correct 71 ms 127480 KB Output is correct
6 Correct 66 ms 127480 KB Output is correct
7 Correct 74 ms 127480 KB Output is correct
8 Correct 70 ms 127480 KB Output is correct
9 Correct 66 ms 127484 KB Output is correct
10 Correct 66 ms 127480 KB Output is correct
11 Correct 67 ms 127480 KB Output is correct
12 Correct 65 ms 127608 KB Output is correct
13 Correct 67 ms 127480 KB Output is correct
14 Correct 65 ms 127484 KB Output is correct
15 Correct 66 ms 127480 KB Output is correct
16 Correct 66 ms 127492 KB Output is correct
17 Correct 68 ms 127480 KB Output is correct
18 Correct 65 ms 127484 KB Output is correct
19 Correct 67 ms 127484 KB Output is correct
20 Correct 67 ms 127480 KB Output is correct
21 Correct 66 ms 127608 KB Output is correct
22 Correct 72 ms 127480 KB Output is correct
23 Correct 66 ms 127480 KB Output is correct
24 Correct 65 ms 127480 KB Output is correct
25 Correct 65 ms 127480 KB Output is correct
26 Correct 70 ms 127440 KB Output is correct
27 Correct 67 ms 127480 KB Output is correct
28 Correct 67 ms 127632 KB Output is correct
29 Correct 65 ms 127480 KB Output is correct
30 Correct 66 ms 127480 KB Output is correct
31 Correct 67 ms 127480 KB Output is correct
32 Correct 68 ms 127484 KB Output is correct
33 Correct 65 ms 127480 KB Output is correct
34 Correct 66 ms 127480 KB Output is correct
35 Correct 97 ms 127480 KB Output is correct
36 Correct 264 ms 127492 KB Output is correct
37 Correct 155 ms 127516 KB Output is correct
38 Correct 97 ms 127480 KB Output is correct
39 Correct 142 ms 127532 KB Output is correct
40 Correct 199 ms 127480 KB Output is correct
41 Correct 99 ms 127480 KB Output is correct
42 Correct 91 ms 127480 KB Output is correct
43 Correct 93 ms 127480 KB Output is correct
44 Correct 71 ms 127608 KB Output is correct
45 Correct 98 ms 127524 KB Output is correct
46 Correct 89 ms 127480 KB Output is correct
47 Correct 101 ms 127480 KB Output is correct
48 Correct 92 ms 127480 KB Output is correct
49 Correct 90 ms 127480 KB Output is correct
50 Correct 82 ms 127480 KB Output is correct
51 Correct 88 ms 127480 KB Output is correct
52 Correct 71 ms 127524 KB Output is correct
53 Correct 95 ms 127608 KB Output is correct
54 Correct 73 ms 127480 KB Output is correct
55 Correct 95 ms 127532 KB Output is correct
56 Correct 77 ms 127524 KB Output is correct
57 Correct 98 ms 127480 KB Output is correct
58 Correct 77 ms 127608 KB Output is correct
59 Correct 324 ms 127536 KB Output is correct
60 Correct 207 ms 127484 KB Output is correct
61 Correct 322 ms 127608 KB Output is correct
62 Correct 192 ms 127480 KB Output is correct
63 Correct 319 ms 127600 KB Output is correct
64 Correct 200 ms 127480 KB Output is correct
65 Correct 287 ms 127480 KB Output is correct
66 Correct 272 ms 127612 KB Output is correct
67 Correct 237 ms 127480 KB Output is correct
68 Correct 216 ms 127480 KB Output is correct
69 Correct 465 ms 127536 KB Output is correct
70 Correct 325 ms 127608 KB Output is correct
71 Correct 280 ms 127608 KB Output is correct
72 Correct 365 ms 127480 KB Output is correct
73 Correct 252 ms 127484 KB Output is correct
74 Correct 225 ms 127420 KB Output is correct
75 Correct 263 ms 127480 KB Output is correct
76 Correct 329 ms 127480 KB Output is correct
77 Correct 323 ms 127480 KB Output is correct
78 Correct 223 ms 127480 KB Output is correct
79 Correct 229 ms 127480 KB Output is correct
80 Correct 288 ms 127480 KB Output is correct
81 Correct 228 ms 127480 KB Output is correct
82 Correct 242 ms 127480 KB Output is correct
83 Correct 304 ms 127480 KB Output is correct
84 Correct 253 ms 127480 KB Output is correct
85 Correct 279 ms 127480 KB Output is correct
86 Correct 297 ms 127608 KB Output is correct
87 Correct 274 ms 127480 KB Output is correct
88 Correct 359 ms 127608 KB Output is correct
89 Correct 337 ms 127608 KB Output is correct
90 Correct 252 ms 127480 KB Output is correct
91 Correct 333 ms 127480 KB Output is correct
92 Correct 356 ms 127480 KB Output is correct
93 Correct 315 ms 127480 KB Output is correct