답안 #286190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286190 2020-08-30T08:13:31 Z reymontada61 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
159 ms 129528 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
int n, len;
const int MXN = 205;
int pos[MXN], by[MXN];

int dp[MXN][MXN][2][MXN];

priority_queue<pair<int, pair<pair<int, int>, pair<int, int>>>, vector<pair<int, pair<pair<int, int>, pair<int, int>>>>, greater<pair<int, pair<pair<int, int>, pair<int, int>>>>> proc;

bool can(int l, int r) {
	if (r + 1 == l) return true;
	if (l == 1 && r == n) return true;
	return false;
}

int prev(int x) {
	if (x == 1) return n;
	return x - 1;
}

int next(int x) {
	if (x == n) return 1;
	return x + 1;
}

signed main() {

	cin >> n >> len;
	for (int i=1; i<=n; i++) {
		cin >> pos[i];
	}
	for (int i=1; i<=n; i++) {
		cin >> by[i];
	}
	
	if (n == 1) {
		if (min(pos[1], len - pos[1]) <= by[1]) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=n; j++) {
			for (int f=0; f<2; f++) {
				for (int g=0; g<=n; g++) {
					dp[i][j][f][g] = LLONG_MAX;
				}
			}
		}
	}
	
	proc.push({pos[1], {{1, 1}, {0, pos[1] <= by[1]}}});
	proc.push({len-pos[n], {{n, n}, {1, (len - pos[n]) <= by[n]}}});
	
	dp[1][1][0][pos[1] <= by[1]] = pos[1];
	dp[n][n][1][(len - pos[n]) <= by[n]] = len - pos[n];
	int lr = 0;
	
	for (int isi=0; isi<=n; isi++) {
		for (int l=1; l<=n; l++) {
			int r = prev(((l - 1 + isi) % n) + 1);
			for (int f=0; f<2; f++) {
				for (int taken=0; taken<=n; taken++) {
					
					if (dp[l][r][f][taken] == LLONG_MAX) continue;
					
					int mtime = dp[l][r][f][taken];
					lr = max(lr, taken);
					
					int at = (f == 0 ? pos[l] : pos[r]);
					
					if (can(l, r)) continue;
					{
						int before = prev(l);
						int dist = abs(at - pos[before]);
						int will = min(dist, len - dist) + mtime;
						int ntaken = taken + (will <= by[before]);
						dp[before][r][0][ntaken] = min(will, dp[before][r][0][ntaken]);
					}
					
					{
						int after = next(r);
						int dist = abs(at - pos[after]);
						int will = min(dist, len - dist) + mtime;
						int ntaken = taken + (will <= by[after]);
						dp[l][after][1][ntaken] = min(will, dp[l][after][1][ntaken]);
					}
					
				}
			}
		}
	}
	
	cout << lr << endl;
	

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 768 KB Output is correct
17 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 768 KB Output is correct
17 Correct 1 ms 768 KB Output is correct
18 Correct 1 ms 1024 KB Output is correct
19 Correct 1 ms 640 KB Output is correct
20 Correct 1 ms 768 KB Output is correct
21 Correct 1 ms 1024 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 896 KB Output is correct
25 Correct 1 ms 1024 KB Output is correct
26 Correct 1 ms 1024 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1152 KB Output is correct
31 Correct 1 ms 1024 KB Output is correct
32 Correct 1 ms 896 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 768 KB Output is correct
17 Correct 1 ms 768 KB Output is correct
18 Correct 101 ms 103988 KB Output is correct
19 Correct 59 ms 62840 KB Output is correct
20 Correct 27 ms 33408 KB Output is correct
21 Correct 52 ms 59392 KB Output is correct
22 Correct 76 ms 77048 KB Output is correct
23 Correct 25 ms 28416 KB Output is correct
24 Correct 18 ms 22400 KB Output is correct
25 Correct 24 ms 27896 KB Output is correct
26 Correct 8 ms 10624 KB Output is correct
27 Correct 27 ms 29056 KB Output is correct
28 Correct 16 ms 20736 KB Output is correct
29 Correct 25 ms 29688 KB Output is correct
30 Correct 18 ms 23296 KB Output is correct
31 Correct 23 ms 27892 KB Output is correct
32 Correct 11 ms 14592 KB Output is correct
33 Correct 23 ms 27904 KB Output is correct
34 Correct 7 ms 9856 KB Output is correct
35 Correct 20 ms 27264 KB Output is correct
36 Correct 10 ms 12928 KB Output is correct
37 Correct 22 ms 29056 KB Output is correct
38 Correct 12 ms 15872 KB Output is correct
39 Correct 22 ms 30336 KB Output is correct
40 Correct 16 ms 17664 KB Output is correct
41 Correct 132 ms 128248 KB Output is correct
42 Correct 64 ms 86264 KB Output is correct
43 Correct 136 ms 128248 KB Output is correct
44 Correct 62 ms 85240 KB Output is correct
45 Correct 134 ms 128188 KB Output is correct
46 Correct 63 ms 86264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 0 ms 512 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 768 KB Output is correct
17 Correct 1 ms 768 KB Output is correct
18 Correct 1 ms 1024 KB Output is correct
19 Correct 1 ms 640 KB Output is correct
20 Correct 1 ms 768 KB Output is correct
21 Correct 1 ms 1024 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 896 KB Output is correct
25 Correct 1 ms 1024 KB Output is correct
26 Correct 1 ms 1024 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1152 KB Output is correct
31 Correct 1 ms 1024 KB Output is correct
32 Correct 1 ms 896 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 101 ms 103988 KB Output is correct
37 Correct 59 ms 62840 KB Output is correct
38 Correct 27 ms 33408 KB Output is correct
39 Correct 52 ms 59392 KB Output is correct
40 Correct 76 ms 77048 KB Output is correct
41 Correct 25 ms 28416 KB Output is correct
42 Correct 18 ms 22400 KB Output is correct
43 Correct 24 ms 27896 KB Output is correct
44 Correct 8 ms 10624 KB Output is correct
45 Correct 27 ms 29056 KB Output is correct
46 Correct 16 ms 20736 KB Output is correct
47 Correct 25 ms 29688 KB Output is correct
48 Correct 18 ms 23296 KB Output is correct
49 Correct 23 ms 27892 KB Output is correct
50 Correct 11 ms 14592 KB Output is correct
51 Correct 23 ms 27904 KB Output is correct
52 Correct 7 ms 9856 KB Output is correct
53 Correct 20 ms 27264 KB Output is correct
54 Correct 10 ms 12928 KB Output is correct
55 Correct 22 ms 29056 KB Output is correct
56 Correct 12 ms 15872 KB Output is correct
57 Correct 22 ms 30336 KB Output is correct
58 Correct 16 ms 17664 KB Output is correct
59 Correct 132 ms 128248 KB Output is correct
60 Correct 64 ms 86264 KB Output is correct
61 Correct 136 ms 128248 KB Output is correct
62 Correct 62 ms 85240 KB Output is correct
63 Correct 134 ms 128188 KB Output is correct
64 Correct 63 ms 86264 KB Output is correct
65 Correct 115 ms 115704 KB Output is correct
66 Correct 104 ms 106232 KB Output is correct
67 Correct 99 ms 101624 KB Output is correct
68 Correct 91 ms 93820 KB Output is correct
69 Correct 122 ms 114552 KB Output is correct
70 Correct 115 ms 109688 KB Output is correct
71 Correct 107 ms 110840 KB Output is correct
72 Correct 119 ms 112120 KB Output is correct
73 Correct 92 ms 103928 KB Output is correct
74 Correct 97 ms 97016 KB Output is correct
75 Correct 102 ms 107384 KB Output is correct
76 Correct 136 ms 123236 KB Output is correct
77 Correct 124 ms 123256 KB Output is correct
78 Correct 99 ms 94840 KB Output is correct
79 Correct 96 ms 98200 KB Output is correct
80 Correct 130 ms 120572 KB Output is correct
81 Correct 93 ms 99320 KB Output is correct
82 Correct 92 ms 105080 KB Output is correct
83 Correct 129 ms 128412 KB Output is correct
84 Correct 96 ms 109688 KB Output is correct
85 Correct 108 ms 119416 KB Output is correct
86 Correct 105 ms 116964 KB Output is correct
87 Correct 106 ms 107384 KB Output is correct
88 Correct 159 ms 129528 KB Output is correct
89 Correct 135 ms 129528 KB Output is correct
90 Correct 80 ms 108536 KB Output is correct
91 Correct 146 ms 129528 KB Output is correct
92 Correct 137 ms 129528 KB Output is correct
93 Correct 108 ms 126968 KB Output is correct