답안 #201206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201206 2020-02-09T19:24:49 Z maruii 유괴 2 (JOI17_abduction2) C++14
44 / 100
183 ms 12408 KB
#include <bits/stdc++.h>
using namespace std;
 
int H, W, Q;
int A[50005], B[50005];
int pfa[50005], sfa[50005], pfb[50005], sfb[50005];
map<tuple<int, int, int>, long long> D;
 
const int SIZE = 1 << 16;
struct ST {
	int A[2 * SIZE];
	void update(int x, int v) {
		for (x += SIZE; x; x >>= 1) A[x] = max(A[x], v);
	}
	int query(int o, int s, int e, int v) {
	vector<int> a, b;
		for (s += SIZE, e += SIZE; s <= e; s >>=1, e >>= 1) {
			if ( s & 1) a.push_back(s), ++s;
			if (~e & 1) b.push_back(e), --e;
		}
		a.insert(a.end(), b.rbegin(), b.rend());
		if (!o) reverse(a.begin(), a.end());
		for (auto i : a) if (A[i] > v) {
			while (i < SIZE) {
				i <<= 1;
				if (o == 1) { if (A[i] < v) i |= 1; }
				else if (A[i | 1] > v) i |= 1;
			}
			return i - SIZE;
		}
		return 0;
	}
} a, b;
 
long long f(int x, int y, int d) {
	if (!x || !y) return -1e13;
	long long &ret = D[{x, y, d}];
	if (ret) return ret;
	if (d == 0) {
		if (max(pfa[x - 1], sfa[x + 1]) < B[y]) return ret = max(x - 1, H - x);
		int p, q;
		if (sfa[x + 1] < B[y]) p = 0;
		else p = a.query(1, x + 1, H, B[y]);
		if (pfa[x - 1] < B[y]) q = 0;
		else q = a.query(0, 1, x - 1, B[y]);
		return ret = max(abs(x - p) + f(p, y, 1), abs(x - q) + f(q, y, 1));
	}
	else {
		if (max(pfb[y - 1], sfb[y + 1]) < A[x]) return ret = max(y - 1, W - y);
		int p, q;
		if (sfb[y + 1] < A[x]) p = 0;
		else p = b.query(1, y + 1, W, A[x]);
		if (pfb[y - 1] < A[x]) q = 0;
		else q = b.query(0, 1, y - 1, A[x]);
		return ret = max(abs(y - p) + f(x, p, 0), abs(y - q) + f(x, q, 0));
	}
}
 
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> H >> W >> Q;
	for (int i = 1; i <= H; ++i) cin >> A[i], a.update(i, A[i]);
	for (int i = 1; i <= W; ++i) cin >> B[i], b.update(i, B[i]);
	for (int i = 1; i <= H; ++i) pfa[i] = max(pfa[i - 1], A[i]);
	for (int i = 1; i <= W; ++i) pfb[i] = max(pfb[i - 1], B[i]);
	for (int i = H; i; --i) sfa[i] = max(sfa[i + 1], A[i]);
	for (int i = W; i; --i) sfb[i] = max(sfb[i + 1], B[i]);
	for (int i = 0; i < Q; ++i) {
		int x, y; cin >> x >> y;
		printf("%lld\n", max(f(x, y, 0), f(x, y, 1)));
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 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 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 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 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 9 ms 760 KB Output is correct
20 Correct 11 ms 888 KB Output is correct
21 Correct 11 ms 760 KB Output is correct
22 Correct 13 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 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 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 9 ms 760 KB Output is correct
20 Correct 11 ms 888 KB Output is correct
21 Correct 11 ms 760 KB Output is correct
22 Correct 13 ms 1144 KB Output is correct
23 Correct 21 ms 2296 KB Output is correct
24 Correct 25 ms 2296 KB Output is correct
25 Correct 21 ms 2296 KB Output is correct
26 Correct 23 ms 2296 KB Output is correct
27 Correct 22 ms 2296 KB Output is correct
28 Correct 55 ms 10488 KB Output is correct
29 Correct 25 ms 3576 KB Output is correct
30 Correct 153 ms 10104 KB Output is correct
31 Correct 183 ms 12408 KB Output is correct
32 Correct 28 ms 2808 KB Output is correct
33 Correct 63 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 760 KB Output is correct
2 Correct 11 ms 632 KB Output is correct
3 Correct 9 ms 632 KB Output is correct
4 Correct 10 ms 760 KB Output is correct
5 Correct 10 ms 632 KB Output is correct
6 Correct 9 ms 888 KB Output is correct
7 Correct 8 ms 760 KB Output is correct
8 Correct 14 ms 1016 KB Output is correct
9 Correct 15 ms 1016 KB Output is correct
10 Correct 14 ms 1020 KB Output is correct
11 Correct 16 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 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 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 9 ms 760 KB Output is correct
20 Correct 11 ms 888 KB Output is correct
21 Correct 11 ms 760 KB Output is correct
22 Correct 13 ms 1144 KB Output is correct
23 Correct 21 ms 2296 KB Output is correct
24 Correct 25 ms 2296 KB Output is correct
25 Correct 21 ms 2296 KB Output is correct
26 Correct 23 ms 2296 KB Output is correct
27 Correct 22 ms 2296 KB Output is correct
28 Correct 55 ms 10488 KB Output is correct
29 Correct 25 ms 3576 KB Output is correct
30 Correct 153 ms 10104 KB Output is correct
31 Correct 183 ms 12408 KB Output is correct
32 Correct 28 ms 2808 KB Output is correct
33 Correct 63 ms 4856 KB Output is correct
34 Correct 10 ms 760 KB Output is correct
35 Correct 11 ms 632 KB Output is correct
36 Correct 9 ms 632 KB Output is correct
37 Correct 10 ms 760 KB Output is correct
38 Correct 10 ms 632 KB Output is correct
39 Correct 9 ms 888 KB Output is correct
40 Correct 8 ms 760 KB Output is correct
41 Correct 14 ms 1016 KB Output is correct
42 Correct 15 ms 1016 KB Output is correct
43 Correct 14 ms 1020 KB Output is correct
44 Correct 16 ms 1144 KB Output is correct
45 Correct 30 ms 2680 KB Output is correct
46 Correct 32 ms 2808 KB Output is correct
47 Correct 38 ms 2680 KB Output is correct
48 Incorrect 29 ms 2680 KB Output isn't correct
49 Halted 0 ms 0 KB -