Submission #61014

# Submission time Handle Problem Language Result Execution time Memory
61014 2018-07-25T06:01:27 Z 윤교준(#1762) Abduction 2 (JOI17_abduction2) C++11
100 / 100
4302 ms 219480 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define revv(V) reverse(allv(V))
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXH = 50005;
const int MAXW = 50005;

unordered_map<ll, ll> MP;

int AU[17][MAXH], AD[17][MAXH];
int BL[17][MAXW], BR[17][MAXW];

int A[MAXH], B[MAXW];

int H, W, Q;

ll f(int y, int x, int dr) {
	ll key = (((ll(y) << 17) | x) << 3) | dr;
	auto it = MP.find(key);
	if(MP.end() != it) return it->second;

	if(!dr) {
		int Y = y;
		for(int i = 17; i--;) if(AU[i][Y] < B[x])
			Y = min(H, Y + (1<<i));
		Y++;
		if(A[Y] < B[x]) return MP[key] = H-y;
		ll ret = max(f(Y, x, 1), f(Y, x, 3)) + (Y-y);
		return MP[key] = ret;
	} else if(2 == dr) {
		int Y = y;
		for(int i = 17; i--;) if(AD[i][Y] < B[x])
			Y = max(1, Y - (1<<i));
		Y--;
		if(A[Y] < B[x]) return MP[key] = y-1;
		ll ret = max(f(Y, x, 1), f(Y, x, 3)) + (y-Y);
		return MP[key] = ret;
	} else if(1 == dr) {
		int X = x;
		for(int i = 17; i--;) if(BR[i][X] < A[y])
			X = min(W, X + (1<<i));
		X++;
		if(B[X] < A[y]) return MP[key] = W-x;
		ll ret = max(f(y, X, 0), f(y, X, 2)) + (X-x);
		return MP[key] = ret;
	} else {
		int X = x;
		for(int i = 17; i--;) if(BL[i][X] < A[y])
			X = max(1, X - (1<<i));
		X--;
		if(B[X] < A[y]) return MP[key] = x-1;
		ll ret = max(f(y, X, 0), f(y, X, 2)) + (x-X);
		return MP[key] = ret;
	}
}

int main() {
	ios::sync_with_stdio(false);

	cin >> H >> W >> Q;
	for(int i = 1; i <= H; i++) cin >> A[i];
	for(int i = 1; i <= W; i++) cin >> B[i];

	for(int i = 1; i <= H; i++) {
		AU[0][i] = A[i+1];
		AD[0][i] = A[i-1];
	}
	for(int i = 1; i <= W; i++) {
		BL[0][i] = B[i-1];
		BR[0][i] = B[i+1];
	}

	for(int j = 0; j < 16; j++) {
		for(int i = 1; i <= H; i++) {
			AU[j+1][i] = AU[j][i];
			if(i + (1<<j) <= H) upmax(AU[j+1][i], AU[j][i + (1<<j)]);
			AD[j+1][i] = AD[j][i];
			if(0 < i - (1<<j)) upmax(AD[j+1][i], AD[j][i - (1<<j)]);
		}
		for(int i = 1; i <= W; i++) {
			BL[j+1][i] = BL[j][i];
			if(0 < i - (1<<j)) upmax(BL[j+1][i], BL[j][i - (1<<j)]);
			BR[j+1][i] = BR[j][i];
			if(i + (1<<j) <= W) upmax(BR[j+1][i], BR[j][i + (1<<j)]);
		}
	}

	for(int y, x; Q--;) {
		cin >> y >> x;
		ll ret = 0;
		for(int dr = 0; dr < 4; dr++)
			upmax(ret, f(y, x, dr));
		printf("%lld\n", ret);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 3 ms 808 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 3 ms 884 KB Output is correct
7 Correct 3 ms 884 KB Output is correct
8 Correct 3 ms 884 KB Output is correct
9 Correct 3 ms 884 KB Output is correct
10 Correct 3 ms 884 KB Output is correct
11 Correct 3 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 3 ms 808 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 3 ms 884 KB Output is correct
7 Correct 3 ms 884 KB Output is correct
8 Correct 3 ms 884 KB Output is correct
9 Correct 3 ms 884 KB Output is correct
10 Correct 3 ms 884 KB Output is correct
11 Correct 3 ms 956 KB Output is correct
12 Correct 4 ms 1468 KB Output is correct
13 Correct 4 ms 1468 KB Output is correct
14 Correct 7 ms 1468 KB Output is correct
15 Correct 4 ms 1468 KB Output is correct
16 Correct 5 ms 1468 KB Output is correct
17 Correct 5 ms 1468 KB Output is correct
18 Correct 4 ms 1516 KB Output is correct
19 Correct 5 ms 1644 KB Output is correct
20 Correct 8 ms 1772 KB Output is correct
21 Correct 7 ms 1772 KB Output is correct
22 Correct 8 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 3 ms 808 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 3 ms 884 KB Output is correct
7 Correct 3 ms 884 KB Output is correct
8 Correct 3 ms 884 KB Output is correct
9 Correct 3 ms 884 KB Output is correct
10 Correct 3 ms 884 KB Output is correct
11 Correct 3 ms 956 KB Output is correct
12 Correct 4 ms 1468 KB Output is correct
13 Correct 4 ms 1468 KB Output is correct
14 Correct 7 ms 1468 KB Output is correct
15 Correct 4 ms 1468 KB Output is correct
16 Correct 5 ms 1468 KB Output is correct
17 Correct 5 ms 1468 KB Output is correct
18 Correct 4 ms 1516 KB Output is correct
19 Correct 5 ms 1644 KB Output is correct
20 Correct 8 ms 1772 KB Output is correct
21 Correct 7 ms 1772 KB Output is correct
22 Correct 8 ms 2028 KB Output is correct
23 Correct 34 ms 14316 KB Output is correct
24 Correct 40 ms 14316 KB Output is correct
25 Correct 38 ms 14316 KB Output is correct
26 Correct 47 ms 14316 KB Output is correct
27 Correct 52 ms 14316 KB Output is correct
28 Correct 69 ms 19228 KB Output is correct
29 Correct 38 ms 19228 KB Output is correct
30 Correct 115 ms 21824 KB Output is correct
31 Correct 144 ms 23392 KB Output is correct
32 Correct 37 ms 23392 KB Output is correct
33 Correct 52 ms 23392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 23392 KB Output is correct
2 Correct 7 ms 23392 KB Output is correct
3 Correct 6 ms 23392 KB Output is correct
4 Correct 6 ms 23392 KB Output is correct
5 Correct 6 ms 23392 KB Output is correct
6 Correct 6 ms 23392 KB Output is correct
7 Correct 6 ms 23392 KB Output is correct
8 Correct 11 ms 23392 KB Output is correct
9 Correct 9 ms 23392 KB Output is correct
10 Correct 8 ms 23392 KB Output is correct
11 Correct 11 ms 23392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 3 ms 808 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 3 ms 884 KB Output is correct
7 Correct 3 ms 884 KB Output is correct
8 Correct 3 ms 884 KB Output is correct
9 Correct 3 ms 884 KB Output is correct
10 Correct 3 ms 884 KB Output is correct
11 Correct 3 ms 956 KB Output is correct
12 Correct 4 ms 1468 KB Output is correct
13 Correct 4 ms 1468 KB Output is correct
14 Correct 7 ms 1468 KB Output is correct
15 Correct 4 ms 1468 KB Output is correct
16 Correct 5 ms 1468 KB Output is correct
17 Correct 5 ms 1468 KB Output is correct
18 Correct 4 ms 1516 KB Output is correct
19 Correct 5 ms 1644 KB Output is correct
20 Correct 8 ms 1772 KB Output is correct
21 Correct 7 ms 1772 KB Output is correct
22 Correct 8 ms 2028 KB Output is correct
23 Correct 34 ms 14316 KB Output is correct
24 Correct 40 ms 14316 KB Output is correct
25 Correct 38 ms 14316 KB Output is correct
26 Correct 47 ms 14316 KB Output is correct
27 Correct 52 ms 14316 KB Output is correct
28 Correct 69 ms 19228 KB Output is correct
29 Correct 38 ms 19228 KB Output is correct
30 Correct 115 ms 21824 KB Output is correct
31 Correct 144 ms 23392 KB Output is correct
32 Correct 37 ms 23392 KB Output is correct
33 Correct 52 ms 23392 KB Output is correct
34 Correct 7 ms 23392 KB Output is correct
35 Correct 7 ms 23392 KB Output is correct
36 Correct 6 ms 23392 KB Output is correct
37 Correct 6 ms 23392 KB Output is correct
38 Correct 6 ms 23392 KB Output is correct
39 Correct 6 ms 23392 KB Output is correct
40 Correct 6 ms 23392 KB Output is correct
41 Correct 11 ms 23392 KB Output is correct
42 Correct 9 ms 23392 KB Output is correct
43 Correct 8 ms 23392 KB Output is correct
44 Correct 11 ms 23392 KB Output is correct
45 Correct 52 ms 23392 KB Output is correct
46 Correct 43 ms 23392 KB Output is correct
47 Correct 39 ms 23392 KB Output is correct
48 Correct 38 ms 23392 KB Output is correct
49 Correct 49 ms 23392 KB Output is correct
50 Correct 103 ms 23392 KB Output is correct
51 Correct 89 ms 23392 KB Output is correct
52 Correct 265 ms 27824 KB Output is correct
53 Correct 224 ms 27824 KB Output is correct
54 Correct 228 ms 27824 KB Output is correct
55 Correct 282 ms 31752 KB Output is correct
56 Correct 4302 ms 219480 KB Output is correct
57 Correct 989 ms 219480 KB Output is correct
58 Correct 938 ms 219480 KB Output is correct
59 Correct 1083 ms 219480 KB Output is correct