답안 #61031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61031 2018-07-25T06:17:41 Z 김세빈(#1761) 유괴 2 (JOI17_abduction2) C++11
44 / 100
213 ms 22084 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

unordered_map <ll, int> M;
int A[50505], B[50505];
int AL[17][50505], AR[17][50505], BL[17][50505], BR[17][50505];
int n, m;

int f(int x, int y, int d)
{
	ll v = (ll) (x - 1) * m * 2 + (y - 1) * 2 + d;
	
	if(M[v]) return M[v];
	
	int l, r, ret, i;
	
	if(d == 0){
		l = y - 1, r = y + 1;
		for(i=16; i>=0; i--){
			if(l - (1<<i) + 1 >= 1 && BL[i][l] <= A[x]) l -= 1<<i;
			if(r + (1<<i) - 1 <= m && BR[i][r] <= A[x]) r += 1<<i;
		}
		l = l < 1? (y - 1) : (y - l) + f(x, l, 1);
		r = r > m? (m - y) : (r - y) + f(x, r, 1);
		ret = max(l, r);
	}
	else{
		l = x - 1, r = x + 1;
		for(i=16; i>=0; i--){
			if(l - (1<<i) + 1 >= 1 && AL[i][l] <= B[y]) l -= 1<<i;
			if(r + (1<<i) - 1 <= n && AR[i][r] <= B[y]) r += 1<<i;
		}
		l = l < 1? (x - 1) : (x - l) + f(l, y, 0);
		r = r > n? (n - x) : (r - x) + f(r, y, 0);
		ret = max(l, r);
	}
//	printf("%d %d %d %d\n", x, y, d, ret);
	
	return M[v] = ret;
}

int main()
{
	int q, i, j, a, b;
	
	scanf("%d%d%d", &n, &m, &q);
	
	for(i=1; i<=n; i++){
		scanf("%d", A+i);
		AL[0][i] = AR[0][i] = A[i];
	}
	
	for(i=1; i<=16; i++){
		for(j=1; j<=n; j++){
			if(j - (1<<i) + 1 >= 1) AL[i][j] = max(AL[i-1][j], AL[i-1][j - (1<<i-1)]);
			if(j + (1<<i) - 1 <= n) AR[i][j] = max(AR[i-1][j], AR[i-1][j + (1<<i-1)]);
		}
	}
	
	for(i=1; i<=m; i++){
		scanf("%d", B+i);
		BL[0][i] = BR[0][i] = B[i];
	}
	
	for(i=1; i<=16; i++){
		for(j=1; j<=m; j++){
			if(j - (1<<i) + 1 >= 1) BL[i][j] = max(BL[i-1][j], BL[i-1][j - (1<<i-1)]);
			if(j + (1<<i) - 1 <= m) BR[i][j] = max(BR[i-1][j], BR[i-1][j + (1<<i-1)]);
		}
	}
	
	for(; q--; ){
		scanf("%d%d", &a, &b);
		printf("%d\n", max(f(a, b, 0), f(a, b, 1)));
	}
	
	return 0;
}

Compilation message

abduction2.cpp: In function 'int main()':
abduction2.cpp:58:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    if(j - (1<<i) + 1 >= 1) AL[i][j] = max(AL[i-1][j], AL[i-1][j - (1<<i-1)]);
                                                                       ~^~
abduction2.cpp:59:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    if(j + (1<<i) - 1 <= n) AR[i][j] = max(AR[i-1][j], AR[i-1][j + (1<<i-1)]);
                                                                       ~^~
abduction2.cpp:70:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    if(j - (1<<i) + 1 >= 1) BL[i][j] = max(BL[i-1][j], BL[i-1][j - (1<<i-1)]);
                                                                       ~^~
abduction2.cpp:71:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    if(j + (1<<i) - 1 <= m) BR[i][j] = max(BR[i-1][j], BR[i-1][j + (1<<i-1)]);
                                                                       ~^~
abduction2.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", A+i);
   ~~~~~^~~~~~~~~~~
abduction2.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", B+i);
   ~~~~~^~~~~~~~~~~
abduction2.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 4 ms 644 KB Output is correct
9 Correct 3 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 4 ms 644 KB Output is correct
9 Correct 3 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
12 Correct 6 ms 1132 KB Output is correct
13 Correct 4 ms 1132 KB Output is correct
14 Correct 5 ms 1132 KB Output is correct
15 Correct 4 ms 1132 KB Output is correct
16 Correct 4 ms 1260 KB Output is correct
17 Correct 5 ms 1260 KB Output is correct
18 Correct 4 ms 1260 KB Output is correct
19 Correct 4 ms 1260 KB Output is correct
20 Correct 5 ms 1332 KB Output is correct
21 Correct 4 ms 1332 KB Output is correct
22 Correct 6 ms 1404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 4 ms 644 KB Output is correct
9 Correct 3 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
12 Correct 6 ms 1132 KB Output is correct
13 Correct 4 ms 1132 KB Output is correct
14 Correct 5 ms 1132 KB Output is correct
15 Correct 4 ms 1132 KB Output is correct
16 Correct 4 ms 1260 KB Output is correct
17 Correct 5 ms 1260 KB Output is correct
18 Correct 4 ms 1260 KB Output is correct
19 Correct 4 ms 1260 KB Output is correct
20 Correct 5 ms 1332 KB Output is correct
21 Correct 4 ms 1332 KB Output is correct
22 Correct 6 ms 1404 KB Output is correct
23 Correct 43 ms 12796 KB Output is correct
24 Correct 38 ms 12796 KB Output is correct
25 Correct 37 ms 12796 KB Output is correct
26 Correct 38 ms 12796 KB Output is correct
27 Correct 42 ms 12796 KB Output is correct
28 Correct 74 ms 16172 KB Output is correct
29 Correct 41 ms 16172 KB Output is correct
30 Correct 98 ms 16904 KB Output is correct
31 Correct 119 ms 17844 KB Output is correct
32 Correct 49 ms 17844 KB Output is correct
33 Correct 57 ms 17844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 17844 KB Output is correct
2 Correct 5 ms 17844 KB Output is correct
3 Correct 6 ms 17844 KB Output is correct
4 Correct 4 ms 17844 KB Output is correct
5 Correct 6 ms 17844 KB Output is correct
6 Correct 6 ms 17844 KB Output is correct
7 Correct 5 ms 17844 KB Output is correct
8 Correct 7 ms 17844 KB Output is correct
9 Correct 6 ms 17844 KB Output is correct
10 Correct 6 ms 17844 KB Output is correct
11 Correct 8 ms 17844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 4 ms 644 KB Output is correct
9 Correct 3 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
12 Correct 6 ms 1132 KB Output is correct
13 Correct 4 ms 1132 KB Output is correct
14 Correct 5 ms 1132 KB Output is correct
15 Correct 4 ms 1132 KB Output is correct
16 Correct 4 ms 1260 KB Output is correct
17 Correct 5 ms 1260 KB Output is correct
18 Correct 4 ms 1260 KB Output is correct
19 Correct 4 ms 1260 KB Output is correct
20 Correct 5 ms 1332 KB Output is correct
21 Correct 4 ms 1332 KB Output is correct
22 Correct 6 ms 1404 KB Output is correct
23 Correct 43 ms 12796 KB Output is correct
24 Correct 38 ms 12796 KB Output is correct
25 Correct 37 ms 12796 KB Output is correct
26 Correct 38 ms 12796 KB Output is correct
27 Correct 42 ms 12796 KB Output is correct
28 Correct 74 ms 16172 KB Output is correct
29 Correct 41 ms 16172 KB Output is correct
30 Correct 98 ms 16904 KB Output is correct
31 Correct 119 ms 17844 KB Output is correct
32 Correct 49 ms 17844 KB Output is correct
33 Correct 57 ms 17844 KB Output is correct
34 Correct 5 ms 17844 KB Output is correct
35 Correct 5 ms 17844 KB Output is correct
36 Correct 6 ms 17844 KB Output is correct
37 Correct 4 ms 17844 KB Output is correct
38 Correct 6 ms 17844 KB Output is correct
39 Correct 6 ms 17844 KB Output is correct
40 Correct 5 ms 17844 KB Output is correct
41 Correct 7 ms 17844 KB Output is correct
42 Correct 6 ms 17844 KB Output is correct
43 Correct 6 ms 17844 KB Output is correct
44 Correct 8 ms 17844 KB Output is correct
45 Correct 44 ms 17844 KB Output is correct
46 Correct 59 ms 17844 KB Output is correct
47 Correct 64 ms 17844 KB Output is correct
48 Correct 41 ms 17844 KB Output is correct
49 Correct 44 ms 17844 KB Output is correct
50 Correct 86 ms 17844 KB Output is correct
51 Correct 84 ms 17844 KB Output is correct
52 Correct 164 ms 19760 KB Output is correct
53 Correct 140 ms 19760 KB Output is correct
54 Correct 128 ms 19760 KB Output is correct
55 Incorrect 213 ms 22084 KB Output isn't correct
56 Halted 0 ms 0 KB -