답안 #203333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203333 2020-02-20T09:03:33 Z staniewzki Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
647 ms 448928 KB
#include<bits/stdc++.h>
using namespace std;

ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }

using LL = long long;
using PII = pair<LL, LL>;

template<class T> auto create(T x) { return x; }
int create(int n) { return n; }
template<class... Ts> auto create(int n, Ts... x) {
	return vector(n, create(x...));
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, len;
	cin >> n >> len;
	vector<int> x(n), t(n);
	REP(i, n) cin >> x[i];
	REP(i, n) cin >> t[i];

	auto dp = create(n + 1, n + 1, n + 1, 2, LL(1e9 + 1));

	vector<int> d(n + 2);
	FOR(i, 1, n) d[i] = x[i - 1];
	d[n + 1] = len;

	auto left = [&](int a, int b) { return d[b] - d[a]; };
	auto right = [&](int a, int b) { return d[n + 1 - a] - d[n + 1 - b]; };

	dp[0][0][0][0] = 0;
	dp[0][0][0][1] = 0;
	int ans = 0;

	FOR(l, 0, n) FOR(r, 0, n) {
		if(l + r > n) break;
		FOR(k, 0, n) {
			if(l) {
				dp[l][r][k][0] = min(dp[l][r][k][0], dp[l - 1][r][k][0] + left(l - 1, l));
				dp[l][r][k][0] = min(dp[l][r][k][0], dp[l - 1][r][k][1] + left(0, l) + right(0, r));
			}
			if(r) {
				dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r - 1][k][1] + right(r - 1, r));
				dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r - 1][k][0] + left(0, l) + right(0, r));
			}
		}

		for(int k = n; k >= 1; k--) {
			if(l && dp[l][r][k - 1][0] <= t[l - 1]) {
				dp[l][r][k][0] = dp[l][r][k - 1][0];
				ans = max(ans, k);
			}
			if(r && dp[l][r][k - 1][1] <= t[n - r]) {
				dp[l][r][k][1] = dp[l][r][k - 1][1];
				ans = max(ans, k);
			}
		}
	}

	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 508 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 248 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 5 ms 508 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 5 ms 632 KB Output is correct
34 Correct 5 ms 504 KB Output is correct
35 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 508 KB Output is correct
18 Correct 476 ms 322936 KB Output is correct
19 Correct 219 ms 152568 KB Output is correct
20 Correct 90 ms 59512 KB Output is correct
21 Correct 210 ms 140024 KB Output is correct
22 Correct 313 ms 206456 KB Output is correct
23 Correct 75 ms 46712 KB Output is correct
24 Correct 52 ms 32376 KB Output is correct
25 Correct 74 ms 45176 KB Output is correct
26 Correct 20 ms 10740 KB Output is correct
27 Correct 75 ms 48120 KB Output is correct
28 Correct 47 ms 29044 KB Output is correct
29 Correct 76 ms 49656 KB Output is correct
30 Correct 62 ms 34684 KB Output is correct
31 Correct 71 ms 45180 KB Output is correct
32 Correct 30 ms 17272 KB Output is correct
33 Correct 69 ms 45176 KB Output is correct
34 Correct 19 ms 9720 KB Output is correct
35 Correct 69 ms 43768 KB Output is correct
36 Correct 25 ms 14328 KB Output is correct
37 Correct 74 ms 48120 KB Output is correct
38 Correct 34 ms 19576 KB Output is correct
39 Correct 79 ms 51064 KB Output is correct
40 Correct 37 ms 23032 KB Output is correct
41 Correct 643 ms 442616 KB Output is correct
42 Correct 341 ms 244584 KB Output is correct
43 Correct 618 ms 442564 KB Output is correct
44 Correct 347 ms 239992 KB Output is correct
45 Correct 618 ms 442488 KB Output is correct
46 Correct 348 ms 244812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 508 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 504 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 248 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 5 ms 508 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 5 ms 632 KB Output is correct
34 Correct 5 ms 504 KB Output is correct
35 Correct 5 ms 504 KB Output is correct
36 Correct 476 ms 322936 KB Output is correct
37 Correct 219 ms 152568 KB Output is correct
38 Correct 90 ms 59512 KB Output is correct
39 Correct 210 ms 140024 KB Output is correct
40 Correct 313 ms 206456 KB Output is correct
41 Correct 75 ms 46712 KB Output is correct
42 Correct 52 ms 32376 KB Output is correct
43 Correct 74 ms 45176 KB Output is correct
44 Correct 20 ms 10740 KB Output is correct
45 Correct 75 ms 48120 KB Output is correct
46 Correct 47 ms 29044 KB Output is correct
47 Correct 76 ms 49656 KB Output is correct
48 Correct 62 ms 34684 KB Output is correct
49 Correct 71 ms 45180 KB Output is correct
50 Correct 30 ms 17272 KB Output is correct
51 Correct 69 ms 45176 KB Output is correct
52 Correct 19 ms 9720 KB Output is correct
53 Correct 69 ms 43768 KB Output is correct
54 Correct 25 ms 14328 KB Output is correct
55 Correct 74 ms 48120 KB Output is correct
56 Correct 34 ms 19576 KB Output is correct
57 Correct 79 ms 51064 KB Output is correct
58 Correct 37 ms 23032 KB Output is correct
59 Correct 643 ms 442616 KB Output is correct
60 Correct 341 ms 244584 KB Output is correct
61 Correct 618 ms 442564 KB Output is correct
62 Correct 347 ms 239992 KB Output is correct
63 Correct 618 ms 442488 KB Output is correct
64 Correct 348 ms 244812 KB Output is correct
65 Correct 555 ms 379640 KB Output is correct
66 Correct 468 ms 333944 KB Output is correct
67 Correct 449 ms 312492 KB Output is correct
68 Correct 389 ms 276804 KB Output is correct
69 Correct 524 ms 373408 KB Output is correct
70 Correct 504 ms 350200 KB Output is correct
71 Correct 509 ms 356216 KB Output is correct
72 Correct 510 ms 361848 KB Output is correct
73 Correct 459 ms 322936 KB Output is correct
74 Correct 427 ms 292088 KB Output is correct
75 Correct 480 ms 339064 KB Output is correct
76 Correct 581 ms 416632 KB Output is correct
77 Correct 575 ms 416632 KB Output is correct
78 Correct 419 ms 281980 KB Output is correct
79 Correct 416 ms 296696 KB Output is correct
80 Correct 583 ms 404088 KB Output is correct
81 Correct 433 ms 301944 KB Output is correct
82 Correct 469 ms 328056 KB Output is correct
83 Correct 601 ms 442488 KB Output is correct
84 Correct 576 ms 350404 KB Output is correct
85 Correct 561 ms 397564 KB Output is correct
86 Correct 547 ms 385272 KB Output is correct
87 Correct 470 ms 339060 KB Output is correct
88 Correct 647 ms 448928 KB Output is correct
89 Correct 628 ms 448892 KB Output is correct
90 Correct 479 ms 344824 KB Output is correct
91 Correct 628 ms 448912 KB Output is correct
92 Correct 635 ms 448888 KB Output is correct
93 Correct 603 ms 435704 KB Output is correct