답안 #331436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331436 2020-11-28T13:28:38 Z syy Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
367 ms 135424 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n, l, x[205], t[205], num[2][205], ans, memo[205][205][2][205];

ll dp(ll i, ll j, bool k, ll s) {
	//visited first i ACW, first j CW, now at (k ? CW : ACW), having taken s stamps
	//returns minimum time taken
	if (i < 0 or j < 0) return LLINF;
	if (i == 0 and j == 0) return (s == 0 ? 0 : LLINF);
	if (i == 0) {
		if (!k) return (num[0][j] >= s ? x[j] : LLINF);
		else return (num[0][j] >= s ? 2*x[j] : LLINF);
	}
	if (j == 0) {
		if (k) return (num[1][i] >= s ? (l-x[n-i+1]) : LLINF);
		else return (num[1][i] >= s ? 2 * (l-x[n-i+1]) : LLINF);
	}
	if (memo[i][j][k][s] != -1) return memo[i][j][k][s];
	ll res = LLINF;
	if (!k) {
		res = min({res, dp(i, j-1, k, s) + x[j] - x[j-1], dp(i, j-1, !k, s) + x[j] + (l-x[n-i+1])});
		if (s) {
			ll y = min(dp(i, j-1, k, s-1) + x[j] - x[j-1], dp(i, j-1, !k, s-1) + x[j] + (l-x[n-i+1]));
			//~ if (i == 1 and j == 3 and s == 4) cout << "hi " << y << "\n";
			if (y <= t[j]) res = min(res, y);
		}
	} else {
		res = min({res, dp(i-1, j, k, s) + x[n-i+2] - x[n-i+1], dp(i-1, j, !k, s) + x[j] + (l-x[n-i+1])});
		if (s) {
			ll y = min(dp(i-1, j, k, s-1) + x[n-i+2] - x[n-i+1], dp(i-1, j, !k, s-1) + x[j] + (l-x[n-i+1]));
			if (y <= t[n-i+1]) res = min(res, y);
		}
	}
	return memo[i][j][k][s] = res;
}

int main() {
	fastio; cin >> n >> l;
	FOR(i, 1, n) cin >> x[i];
	FOR(i, 1, n) cin >> t[i];
	FOR(i, 1, n) num[0][i] = num[0][i-1] + (x[i] <= t[i]);
	FOR(i, 1, n) num[1][i] = num[1][i-1] + ((l-x[n-i+1]) <= t[n-i+1]);
	x[0] = 0, x[n+1] = l;
	memset(memo, -1, sizeof memo);
	//~ cout << dp(1, 3, 0, 4) << "\n";
	//~ FOR(i, 0, n) FOR(j, 0, n-i) FOR(k, 0, 1) FOR(m, 0, n) printf("%lld %lld %lld %lld: %lld\n", i, j, k, m, dp(i, j, k, m));
	FOR(i, 0, n) FOR(j, 0, n-i) FOR(k, 1, n) if (min(dp(i, j, 0, k), dp(i, j, 1, k)) < (ll) 2e12) ans = max(ans, k);
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 78 ms 135276 KB Output is correct
4 Correct 71 ms 135276 KB Output is correct
5 Correct 70 ms 135276 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 75 ms 135276 KB Output is correct
8 Correct 73 ms 135296 KB Output is correct
9 Correct 72 ms 135276 KB Output is correct
10 Correct 86 ms 135276 KB Output is correct
11 Correct 70 ms 135276 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 70 ms 135404 KB Output is correct
14 Correct 71 ms 135248 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 71 ms 135300 KB Output is correct
17 Correct 71 ms 135276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 78 ms 135276 KB Output is correct
4 Correct 71 ms 135276 KB Output is correct
5 Correct 70 ms 135276 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 75 ms 135276 KB Output is correct
8 Correct 73 ms 135296 KB Output is correct
9 Correct 72 ms 135276 KB Output is correct
10 Correct 86 ms 135276 KB Output is correct
11 Correct 70 ms 135276 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 70 ms 135404 KB Output is correct
14 Correct 71 ms 135248 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 71 ms 135300 KB Output is correct
17 Correct 71 ms 135276 KB Output is correct
18 Correct 69 ms 135276 KB Output is correct
19 Correct 72 ms 135276 KB Output is correct
20 Correct 71 ms 135276 KB Output is correct
21 Correct 72 ms 135276 KB Output is correct
22 Correct 70 ms 135276 KB Output is correct
23 Correct 75 ms 135276 KB Output is correct
24 Correct 74 ms 135276 KB Output is correct
25 Correct 71 ms 135276 KB Output is correct
26 Correct 74 ms 135276 KB Output is correct
27 Correct 70 ms 135276 KB Output is correct
28 Correct 71 ms 135276 KB Output is correct
29 Correct 71 ms 135276 KB Output is correct
30 Correct 71 ms 135276 KB Output is correct
31 Correct 78 ms 135276 KB Output is correct
32 Correct 72 ms 135276 KB Output is correct
33 Correct 72 ms 135276 KB Output is correct
34 Correct 69 ms 135296 KB Output is correct
35 Correct 75 ms 135296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 78 ms 135276 KB Output is correct
4 Correct 71 ms 135276 KB Output is correct
5 Correct 70 ms 135276 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 75 ms 135276 KB Output is correct
8 Correct 73 ms 135296 KB Output is correct
9 Correct 72 ms 135276 KB Output is correct
10 Correct 86 ms 135276 KB Output is correct
11 Correct 70 ms 135276 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 70 ms 135404 KB Output is correct
14 Correct 71 ms 135248 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 71 ms 135300 KB Output is correct
17 Correct 71 ms 135276 KB Output is correct
18 Correct 277 ms 135276 KB Output is correct
19 Correct 167 ms 135276 KB Output is correct
20 Correct 109 ms 135276 KB Output is correct
21 Correct 164 ms 135404 KB Output is correct
22 Correct 198 ms 135276 KB Output is correct
23 Correct 98 ms 135276 KB Output is correct
24 Correct 99 ms 135296 KB Output is correct
25 Correct 120 ms 135276 KB Output is correct
26 Correct 79 ms 135276 KB Output is correct
27 Correct 98 ms 135256 KB Output is correct
28 Correct 88 ms 135296 KB Output is correct
29 Correct 102 ms 135276 KB Output is correct
30 Correct 94 ms 135276 KB Output is correct
31 Correct 98 ms 135276 KB Output is correct
32 Correct 80 ms 135276 KB Output is correct
33 Correct 98 ms 135276 KB Output is correct
34 Correct 77 ms 135276 KB Output is correct
35 Correct 103 ms 135424 KB Output is correct
36 Correct 81 ms 135276 KB Output is correct
37 Correct 102 ms 135276 KB Output is correct
38 Correct 81 ms 135276 KB Output is correct
39 Correct 100 ms 135276 KB Output is correct
40 Correct 88 ms 135276 KB Output is correct
41 Correct 346 ms 135404 KB Output is correct
42 Correct 220 ms 135276 KB Output is correct
43 Correct 347 ms 135276 KB Output is correct
44 Correct 217 ms 135276 KB Output is correct
45 Correct 367 ms 135276 KB Output is correct
46 Correct 219 ms 135276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 78 ms 135276 KB Output is correct
4 Correct 71 ms 135276 KB Output is correct
5 Correct 70 ms 135276 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 75 ms 135276 KB Output is correct
8 Correct 73 ms 135296 KB Output is correct
9 Correct 72 ms 135276 KB Output is correct
10 Correct 86 ms 135276 KB Output is correct
11 Correct 70 ms 135276 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 70 ms 135404 KB Output is correct
14 Correct 71 ms 135248 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 71 ms 135300 KB Output is correct
17 Correct 71 ms 135276 KB Output is correct
18 Correct 69 ms 135276 KB Output is correct
19 Correct 72 ms 135276 KB Output is correct
20 Correct 71 ms 135276 KB Output is correct
21 Correct 72 ms 135276 KB Output is correct
22 Correct 70 ms 135276 KB Output is correct
23 Correct 75 ms 135276 KB Output is correct
24 Correct 74 ms 135276 KB Output is correct
25 Correct 71 ms 135276 KB Output is correct
26 Correct 74 ms 135276 KB Output is correct
27 Correct 70 ms 135276 KB Output is correct
28 Correct 71 ms 135276 KB Output is correct
29 Correct 71 ms 135276 KB Output is correct
30 Correct 71 ms 135276 KB Output is correct
31 Correct 78 ms 135276 KB Output is correct
32 Correct 72 ms 135276 KB Output is correct
33 Correct 72 ms 135276 KB Output is correct
34 Correct 69 ms 135296 KB Output is correct
35 Correct 75 ms 135296 KB Output is correct
36 Correct 277 ms 135276 KB Output is correct
37 Correct 167 ms 135276 KB Output is correct
38 Correct 109 ms 135276 KB Output is correct
39 Correct 164 ms 135404 KB Output is correct
40 Correct 198 ms 135276 KB Output is correct
41 Correct 98 ms 135276 KB Output is correct
42 Correct 99 ms 135296 KB Output is correct
43 Correct 120 ms 135276 KB Output is correct
44 Correct 79 ms 135276 KB Output is correct
45 Correct 98 ms 135256 KB Output is correct
46 Correct 88 ms 135296 KB Output is correct
47 Correct 102 ms 135276 KB Output is correct
48 Correct 94 ms 135276 KB Output is correct
49 Correct 98 ms 135276 KB Output is correct
50 Correct 80 ms 135276 KB Output is correct
51 Correct 98 ms 135276 KB Output is correct
52 Correct 77 ms 135276 KB Output is correct
53 Correct 103 ms 135424 KB Output is correct
54 Correct 81 ms 135276 KB Output is correct
55 Correct 102 ms 135276 KB Output is correct
56 Correct 81 ms 135276 KB Output is correct
57 Correct 100 ms 135276 KB Output is correct
58 Correct 88 ms 135276 KB Output is correct
59 Correct 346 ms 135404 KB Output is correct
60 Correct 220 ms 135276 KB Output is correct
61 Correct 347 ms 135276 KB Output is correct
62 Correct 217 ms 135276 KB Output is correct
63 Correct 367 ms 135276 KB Output is correct
64 Correct 219 ms 135276 KB Output is correct
65 Correct 329 ms 135276 KB Output is correct
66 Correct 278 ms 135276 KB Output is correct
67 Correct 276 ms 135404 KB Output is correct
68 Correct 251 ms 135276 KB Output is correct
69 Correct 307 ms 135404 KB Output is correct
70 Correct 291 ms 135404 KB Output is correct
71 Correct 297 ms 135404 KB Output is correct
72 Correct 347 ms 135404 KB Output is correct
73 Correct 270 ms 135276 KB Output is correct
74 Correct 252 ms 135328 KB Output is correct
75 Correct 319 ms 135276 KB Output is correct
76 Correct 331 ms 135404 KB Output is correct
77 Correct 335 ms 135404 KB Output is correct
78 Correct 244 ms 135276 KB Output is correct
79 Correct 303 ms 135276 KB Output is correct
80 Correct 320 ms 135404 KB Output is correct
81 Correct 257 ms 135404 KB Output is correct
82 Correct 287 ms 135276 KB Output is correct
83 Correct 345 ms 135276 KB Output is correct
84 Correct 300 ms 135276 KB Output is correct
85 Correct 317 ms 135276 KB Output is correct
86 Correct 308 ms 135284 KB Output is correct
87 Correct 279 ms 135276 KB Output is correct
88 Correct 351 ms 135404 KB Output is correct
89 Correct 354 ms 135276 KB Output is correct
90 Correct 291 ms 135344 KB Output is correct
91 Correct 354 ms 135276 KB Output is correct
92 Correct 362 ms 135276 KB Output is correct
93 Correct 337 ms 135404 KB Output is correct