답안 #201211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201211 2020-02-09T19:40:20 Z maruii 유괴 2 (JOI17_abduction2) C++14
13 / 100
7 ms 760 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];
	vector<int> a, b;
	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) {
		a.clear(), b.clear();
		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) {
	long long &ret = D[{x, y, d}];
	if (ret) return ret;
	if (d == 0) {
		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(p ? abs(x - p) + f(p, y, 1) : max(x - 1, H - x), q ? abs(x - q) + f(q, y, 1) : max(x - 1, H - x));
	}
	else {
		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(p ? abs(y - p) + f(x, p, 0) : max(y - 1, W - y), q ? abs(y - q) + f(x, q, 0) : max(y - 1, W - y));
	}
}
 
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 248 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 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 376 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 248 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 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 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Incorrect 5 ms 500 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 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 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Incorrect 5 ms 500 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 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 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Incorrect 5 ms 500 KB Output isn't correct
13 Halted 0 ms 0 KB -