Submission #61011

# Submission time Handle Problem Language Result Execution time Memory
61011 2018-07-25T05:59:31 Z 윤교준(#1762) Abduction 2 (JOI17_abduction2) C++11
44 / 100
409 ms 30852 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, int> MP;

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

int A[MAXH], B[MAXW];

int H, W, Q;

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

	if(!dr) {
		int Y = y;
		for(int i = 16; i--;) if(AU[i][Y] < B[x])
			Y = min(H, Y + (1<<i));
		Y++;
		if(A[Y] < B[x]) return MP[key] = H-y;
		int 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 = 16; i--;) if(AD[i][Y] < B[x])
			Y = max(1, Y - (1<<i));
		Y--;
		if(A[Y] < B[x]) return MP[key] = y-1;
		int 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 = 16; i--;) if(BR[i][X] < A[y])
			X = min(W, X + (1<<i));
		X++;
		if(B[X] < A[y]) return MP[key] = W-x;
		int ret = max(f(y, X, 0), f(y, X, 2)) + (X-x);
		return MP[key] = ret;
	} else {
		int X = x;
		for(int i = 16; i--;) if(BL[i][X] < A[y])
			X = max(1, X - (1<<i));
		X--;
		if(B[X] < A[y]) return MP[key] = x-1;
		int 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 < 15; 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;
		int ret = 0;
		for(int dr = 0; dr < 4; dr++)
			upmax(ret, f(y, x, dr));
		printf("%d\n", ret);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 4 ms 744 KB Output is correct
3 Correct 3 ms 744 KB Output is correct
4 Correct 3 ms 756 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 4 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 2 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 4 ms 744 KB Output is correct
3 Correct 3 ms 744 KB Output is correct
4 Correct 3 ms 756 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 4 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 2 ms 884 KB Output is correct
12 Correct 4 ms 1396 KB Output is correct
13 Correct 4 ms 1396 KB Output is correct
14 Correct 5 ms 1396 KB Output is correct
15 Correct 4 ms 1396 KB Output is correct
16 Correct 4 ms 1396 KB Output is correct
17 Correct 4 ms 1396 KB Output is correct
18 Correct 4 ms 1396 KB Output is correct
19 Correct 6 ms 1652 KB Output is correct
20 Correct 6 ms 1780 KB Output is correct
21 Correct 6 ms 1780 KB Output is correct
22 Correct 7 ms 1924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 4 ms 744 KB Output is correct
3 Correct 3 ms 744 KB Output is correct
4 Correct 3 ms 756 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 4 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 2 ms 884 KB Output is correct
12 Correct 4 ms 1396 KB Output is correct
13 Correct 4 ms 1396 KB Output is correct
14 Correct 5 ms 1396 KB Output is correct
15 Correct 4 ms 1396 KB Output is correct
16 Correct 4 ms 1396 KB Output is correct
17 Correct 4 ms 1396 KB Output is correct
18 Correct 4 ms 1396 KB Output is correct
19 Correct 6 ms 1652 KB Output is correct
20 Correct 6 ms 1780 KB Output is correct
21 Correct 6 ms 1780 KB Output is correct
22 Correct 7 ms 1924 KB Output is correct
23 Correct 51 ms 13536 KB Output is correct
24 Correct 37 ms 13572 KB Output is correct
25 Correct 51 ms 13572 KB Output is correct
26 Correct 37 ms 13572 KB Output is correct
27 Correct 31 ms 13572 KB Output is correct
28 Correct 77 ms 18580 KB Output is correct
29 Correct 45 ms 18580 KB Output is correct
30 Correct 153 ms 21004 KB Output is correct
31 Correct 195 ms 22752 KB Output is correct
32 Correct 39 ms 22752 KB Output is correct
33 Correct 59 ms 22752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 22752 KB Output is correct
2 Correct 7 ms 22752 KB Output is correct
3 Correct 6 ms 22752 KB Output is correct
4 Correct 7 ms 22752 KB Output is correct
5 Correct 6 ms 22752 KB Output is correct
6 Correct 7 ms 22752 KB Output is correct
7 Correct 6 ms 22752 KB Output is correct
8 Correct 9 ms 22752 KB Output is correct
9 Correct 8 ms 22752 KB Output is correct
10 Correct 10 ms 22752 KB Output is correct
11 Correct 10 ms 22752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 4 ms 744 KB Output is correct
3 Correct 3 ms 744 KB Output is correct
4 Correct 3 ms 756 KB Output is correct
5 Correct 3 ms 884 KB Output is correct
6 Correct 4 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 2 ms 884 KB Output is correct
12 Correct 4 ms 1396 KB Output is correct
13 Correct 4 ms 1396 KB Output is correct
14 Correct 5 ms 1396 KB Output is correct
15 Correct 4 ms 1396 KB Output is correct
16 Correct 4 ms 1396 KB Output is correct
17 Correct 4 ms 1396 KB Output is correct
18 Correct 4 ms 1396 KB Output is correct
19 Correct 6 ms 1652 KB Output is correct
20 Correct 6 ms 1780 KB Output is correct
21 Correct 6 ms 1780 KB Output is correct
22 Correct 7 ms 1924 KB Output is correct
23 Correct 51 ms 13536 KB Output is correct
24 Correct 37 ms 13572 KB Output is correct
25 Correct 51 ms 13572 KB Output is correct
26 Correct 37 ms 13572 KB Output is correct
27 Correct 31 ms 13572 KB Output is correct
28 Correct 77 ms 18580 KB Output is correct
29 Correct 45 ms 18580 KB Output is correct
30 Correct 153 ms 21004 KB Output is correct
31 Correct 195 ms 22752 KB Output is correct
32 Correct 39 ms 22752 KB Output is correct
33 Correct 59 ms 22752 KB Output is correct
34 Correct 6 ms 22752 KB Output is correct
35 Correct 7 ms 22752 KB Output is correct
36 Correct 6 ms 22752 KB Output is correct
37 Correct 7 ms 22752 KB Output is correct
38 Correct 6 ms 22752 KB Output is correct
39 Correct 7 ms 22752 KB Output is correct
40 Correct 6 ms 22752 KB Output is correct
41 Correct 9 ms 22752 KB Output is correct
42 Correct 8 ms 22752 KB Output is correct
43 Correct 10 ms 22752 KB Output is correct
44 Correct 10 ms 22752 KB Output is correct
45 Correct 43 ms 22752 KB Output is correct
46 Correct 46 ms 22752 KB Output is correct
47 Correct 51 ms 22752 KB Output is correct
48 Correct 41 ms 22752 KB Output is correct
49 Correct 39 ms 22752 KB Output is correct
50 Correct 98 ms 22752 KB Output is correct
51 Correct 85 ms 22752 KB Output is correct
52 Correct 249 ms 26900 KB Output is correct
53 Correct 285 ms 26900 KB Output is correct
54 Correct 302 ms 26900 KB Output is correct
55 Incorrect 409 ms 30852 KB Output isn't correct
56 Halted 0 ms 0 KB -