답안 #201557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201557 2020-02-11T04:38:09 Z abacaba Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
165 ms 78328 KB
#include <bits/stdc++.h> 
using namespace std;

#define f first
#define se second

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}

template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int N = 2e2 + 15;
int n, x, dp[2][N][N][N], ans;
pair <int, int> a[N];

// dp[last][l][r][items_taken] = min_time

inline int get(int c, int d) {
	return min({abs(a[c].f - a[d].f), abs(a[c].f + x - a[d].f), abs(a[d].f + x - a[c].f)});
}

inline void calc(int l, int r, int len) {
	// FROM L
	int nxt = (l - 1 + n) % n;
	int d = get(l, nxt);
	if(nxt != r) {
		for(int k = 0; k <= len; ++k) {
			if(dp[0][l][r][k] + d <= a[nxt].se)
				Min(dp[0][nxt][r][k+1], dp[0][l][r][k] + d);
			else
				Min(dp[0][nxt][r][k], dp[0][l][r][k] + d);
		}
	}
	nxt = (r + 1 + n) % n;
	if(nxt != l) {
		d = get(l, nxt);
		for(int k = 0; k <= len; ++k) {
			if(dp[0][l][r][k] + d <= a[nxt].se)
				Min(dp[1][l][nxt][k+1], dp[0][l][r][k] + d);
			else
				Min(dp[1][l][nxt][k], dp[0][l][r][k] + d);
		}
	}

	// FROM R
	nxt = (l - 1 + n) % n;
	if(nxt != r) {
		d = get(r, nxt);
		for(int k = 0; k <= len; ++k) {
			if(dp[1][l][r][k] + d <= a[nxt].se)
				Min(dp[0][nxt][r][k+1], dp[1][l][r][k] + d);
			else
				Min(dp[0][nxt][r][k], dp[1][l][r][k] + d);
		}
	}
	nxt = (r + 1 + n) % n;
	if(nxt != l) {
		d = get(r, nxt);
		for(int k = 0; k <= len; ++k) {
			if(dp[1][l][r][k] + d <= a[nxt].se)
				Min(dp[1][l][nxt][k+1], dp[1][l][r][k] + d);
			else
				Min(dp[1][l][nxt][k], dp[1][l][r][k] + d);
		}
	}
}

main() {
	memset(dp, 0x3f, sizeof(dp));
	cin >> n >> x;
	for(int i = 1; i <= n; ++i)
		cin >> a[i].f;
	for(int i = 1; i <= n; ++i)
		cin >> a[i].se;
	reverse(a + 1, a + 1 + n);
	++n;
	dp[0][0][0][0] = 0;
	for(int len = 0; len < n; ++len) {
		for(int l = 0; l < n; ++l) {
			int r = (l + len - 1) % n;
			calc(l, r, len);
		}
	}
	for(int k = n; k >= 0; --k)
		for(int i = 0; i < 2; ++i)
			for(int l = 0; l < n; ++l)
				for(int r = 0; r < n; ++r)
					if(dp[i][l][r][k] != inf) {
						cout << k << endl;
						return 0;
					}
	return 0;
}

Compilation message

ho_t3.cpp:72:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 78072 KB Output is correct
2 Correct 46 ms 78072 KB Output is correct
3 Correct 47 ms 78072 KB Output is correct
4 Correct 45 ms 78072 KB Output is correct
5 Correct 49 ms 78200 KB Output is correct
6 Correct 45 ms 78072 KB Output is correct
7 Correct 46 ms 78072 KB Output is correct
8 Correct 47 ms 78072 KB Output is correct
9 Correct 45 ms 78072 KB Output is correct
10 Correct 46 ms 78072 KB Output is correct
11 Correct 50 ms 78072 KB Output is correct
12 Correct 58 ms 78072 KB Output is correct
13 Correct 46 ms 78072 KB Output is correct
14 Correct 45 ms 78072 KB Output is correct
15 Correct 46 ms 78072 KB Output is correct
16 Correct 45 ms 78204 KB Output is correct
17 Correct 45 ms 78072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 78072 KB Output is correct
2 Correct 46 ms 78072 KB Output is correct
3 Correct 47 ms 78072 KB Output is correct
4 Correct 45 ms 78072 KB Output is correct
5 Correct 49 ms 78200 KB Output is correct
6 Correct 45 ms 78072 KB Output is correct
7 Correct 46 ms 78072 KB Output is correct
8 Correct 47 ms 78072 KB Output is correct
9 Correct 45 ms 78072 KB Output is correct
10 Correct 46 ms 78072 KB Output is correct
11 Correct 50 ms 78072 KB Output is correct
12 Correct 58 ms 78072 KB Output is correct
13 Correct 46 ms 78072 KB Output is correct
14 Correct 45 ms 78072 KB Output is correct
15 Correct 46 ms 78072 KB Output is correct
16 Correct 45 ms 78204 KB Output is correct
17 Correct 45 ms 78072 KB Output is correct
18 Correct 49 ms 78072 KB Output is correct
19 Correct 46 ms 78072 KB Output is correct
20 Correct 44 ms 78076 KB Output is correct
21 Correct 46 ms 78072 KB Output is correct
22 Correct 49 ms 78072 KB Output is correct
23 Correct 47 ms 78072 KB Output is correct
24 Correct 46 ms 78100 KB Output is correct
25 Correct 47 ms 78072 KB Output is correct
26 Correct 45 ms 78072 KB Output is correct
27 Correct 47 ms 78072 KB Output is correct
28 Correct 46 ms 78072 KB Output is correct
29 Correct 47 ms 78072 KB Output is correct
30 Correct 46 ms 78072 KB Output is correct
31 Correct 45 ms 78072 KB Output is correct
32 Correct 47 ms 78072 KB Output is correct
33 Correct 48 ms 78072 KB Output is correct
34 Correct 47 ms 78072 KB Output is correct
35 Correct 46 ms 78072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 78072 KB Output is correct
2 Correct 46 ms 78072 KB Output is correct
3 Correct 47 ms 78072 KB Output is correct
4 Correct 45 ms 78072 KB Output is correct
5 Correct 49 ms 78200 KB Output is correct
6 Correct 45 ms 78072 KB Output is correct
7 Correct 46 ms 78072 KB Output is correct
8 Correct 47 ms 78072 KB Output is correct
9 Correct 45 ms 78072 KB Output is correct
10 Correct 46 ms 78072 KB Output is correct
11 Correct 50 ms 78072 KB Output is correct
12 Correct 58 ms 78072 KB Output is correct
13 Correct 46 ms 78072 KB Output is correct
14 Correct 45 ms 78072 KB Output is correct
15 Correct 46 ms 78072 KB Output is correct
16 Correct 45 ms 78204 KB Output is correct
17 Correct 45 ms 78072 KB Output is correct
18 Correct 99 ms 78200 KB Output is correct
19 Correct 66 ms 78072 KB Output is correct
20 Correct 56 ms 78072 KB Output is correct
21 Correct 67 ms 78072 KB Output is correct
22 Correct 79 ms 78076 KB Output is correct
23 Correct 54 ms 78072 KB Output is correct
24 Correct 51 ms 78072 KB Output is correct
25 Correct 51 ms 78072 KB Output is correct
26 Correct 47 ms 78072 KB Output is correct
27 Correct 52 ms 78072 KB Output is correct
28 Correct 54 ms 78072 KB Output is correct
29 Correct 53 ms 78072 KB Output is correct
30 Correct 54 ms 78072 KB Output is correct
31 Correct 53 ms 78072 KB Output is correct
32 Correct 51 ms 78072 KB Output is correct
33 Correct 53 ms 78072 KB Output is correct
34 Correct 66 ms 78072 KB Output is correct
35 Correct 64 ms 78328 KB Output is correct
36 Correct 50 ms 78072 KB Output is correct
37 Correct 56 ms 78072 KB Output is correct
38 Correct 51 ms 78072 KB Output is correct
39 Correct 58 ms 78072 KB Output is correct
40 Correct 51 ms 78072 KB Output is correct
41 Correct 101 ms 78072 KB Output is correct
42 Correct 110 ms 78072 KB Output is correct
43 Correct 100 ms 78076 KB Output is correct
44 Correct 105 ms 78072 KB Output is correct
45 Correct 101 ms 78072 KB Output is correct
46 Correct 106 ms 78072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 78072 KB Output is correct
2 Correct 46 ms 78072 KB Output is correct
3 Correct 47 ms 78072 KB Output is correct
4 Correct 45 ms 78072 KB Output is correct
5 Correct 49 ms 78200 KB Output is correct
6 Correct 45 ms 78072 KB Output is correct
7 Correct 46 ms 78072 KB Output is correct
8 Correct 47 ms 78072 KB Output is correct
9 Correct 45 ms 78072 KB Output is correct
10 Correct 46 ms 78072 KB Output is correct
11 Correct 50 ms 78072 KB Output is correct
12 Correct 58 ms 78072 KB Output is correct
13 Correct 46 ms 78072 KB Output is correct
14 Correct 45 ms 78072 KB Output is correct
15 Correct 46 ms 78072 KB Output is correct
16 Correct 45 ms 78204 KB Output is correct
17 Correct 45 ms 78072 KB Output is correct
18 Correct 49 ms 78072 KB Output is correct
19 Correct 46 ms 78072 KB Output is correct
20 Correct 44 ms 78076 KB Output is correct
21 Correct 46 ms 78072 KB Output is correct
22 Correct 49 ms 78072 KB Output is correct
23 Correct 47 ms 78072 KB Output is correct
24 Correct 46 ms 78100 KB Output is correct
25 Correct 47 ms 78072 KB Output is correct
26 Correct 45 ms 78072 KB Output is correct
27 Correct 47 ms 78072 KB Output is correct
28 Correct 46 ms 78072 KB Output is correct
29 Correct 47 ms 78072 KB Output is correct
30 Correct 46 ms 78072 KB Output is correct
31 Correct 45 ms 78072 KB Output is correct
32 Correct 47 ms 78072 KB Output is correct
33 Correct 48 ms 78072 KB Output is correct
34 Correct 47 ms 78072 KB Output is correct
35 Correct 46 ms 78072 KB Output is correct
36 Correct 99 ms 78200 KB Output is correct
37 Correct 66 ms 78072 KB Output is correct
38 Correct 56 ms 78072 KB Output is correct
39 Correct 67 ms 78072 KB Output is correct
40 Correct 79 ms 78076 KB Output is correct
41 Correct 54 ms 78072 KB Output is correct
42 Correct 51 ms 78072 KB Output is correct
43 Correct 51 ms 78072 KB Output is correct
44 Correct 47 ms 78072 KB Output is correct
45 Correct 52 ms 78072 KB Output is correct
46 Correct 54 ms 78072 KB Output is correct
47 Correct 53 ms 78072 KB Output is correct
48 Correct 54 ms 78072 KB Output is correct
49 Correct 53 ms 78072 KB Output is correct
50 Correct 51 ms 78072 KB Output is correct
51 Correct 53 ms 78072 KB Output is correct
52 Correct 66 ms 78072 KB Output is correct
53 Correct 64 ms 78328 KB Output is correct
54 Correct 50 ms 78072 KB Output is correct
55 Correct 56 ms 78072 KB Output is correct
56 Correct 51 ms 78072 KB Output is correct
57 Correct 58 ms 78072 KB Output is correct
58 Correct 51 ms 78072 KB Output is correct
59 Correct 101 ms 78072 KB Output is correct
60 Correct 110 ms 78072 KB Output is correct
61 Correct 100 ms 78076 KB Output is correct
62 Correct 105 ms 78072 KB Output is correct
63 Correct 101 ms 78072 KB Output is correct
64 Correct 106 ms 78072 KB Output is correct
65 Correct 102 ms 78072 KB Output is correct
66 Correct 96 ms 78044 KB Output is correct
67 Correct 97 ms 78072 KB Output is correct
68 Correct 93 ms 78072 KB Output is correct
69 Correct 106 ms 78072 KB Output is correct
70 Correct 76 ms 78076 KB Output is correct
71 Correct 103 ms 78072 KB Output is correct
72 Correct 76 ms 78072 KB Output is correct
73 Correct 105 ms 78204 KB Output is correct
74 Correct 75 ms 78072 KB Output is correct
75 Correct 102 ms 78072 KB Output is correct
76 Correct 95 ms 78072 KB Output is correct
77 Correct 123 ms 78080 KB Output is correct
78 Correct 80 ms 78200 KB Output is correct
79 Correct 89 ms 78072 KB Output is correct
80 Correct 88 ms 78072 KB Output is correct
81 Correct 100 ms 78200 KB Output is correct
82 Correct 106 ms 78072 KB Output is correct
83 Correct 132 ms 78072 KB Output is correct
84 Correct 108 ms 78072 KB Output is correct
85 Correct 104 ms 78072 KB Output is correct
86 Correct 119 ms 78072 KB Output is correct
87 Correct 106 ms 78244 KB Output is correct
88 Correct 79 ms 78072 KB Output is correct
89 Correct 101 ms 78152 KB Output is correct
90 Correct 128 ms 78072 KB Output is correct
91 Correct 78 ms 78072 KB Output is correct
92 Correct 97 ms 78072 KB Output is correct
93 Correct 165 ms 78072 KB Output is correct