답안 #61163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61163 2018-07-25T09:41:37 Z ainta 유괴 2 (JOI17_abduction2) C++17
100 / 100
4181 ms 252144 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#define N_ 51000
#define SZ 65536
using namespace std;
int n, m, Q;
map<long long, long long>Map;
int X[N_], Y[N_];
long long Num(int x, int y, int dir) {
	return ((((long long)x << 16) + y) << 2) + dir;
}
struct Tree {
	int M[SZ+SZ];
	void Put(int a, int b) {
		a += SZ;
		M[a] = b;
		while (a != 1) {
			a >>= 1;
			M[a] = max(M[a * 2], M[a * 2 + 1]);
		}
	}
	int Before(int a, int g) {
		int b = SZ, e = a + SZ - 1, r = 0;
		while (b <= e) {
			if (M[e] > g) {
				r = e;
				break;
			}
			b = (b + 1) >> 1, e = (e - 1) >> 1;
		}
		if (r == 0)return r;
		while (r < SZ) {
			r *= 2;
			if (M[r + 1] > g)r++;
		}
		return r - SZ;
	}
	int Next(int a, int g) {
		int b = a + SZ + 1, e = SZ + SZ - 1, r = 1e9;
		while (b <= e) {
			if (M[b] > g) {
				r = b;
				break;
			}
			b = (b + 1) >> 1, e = (e - 1) >> 1;
		}
		if (r > 8e8)return r;
		while (r < SZ) {
			r *= 2;
			if (M[r] <= g)r++;
		}
		return r - SZ;
	}
}IT[2];
int Calc(int x, int y, int dir) {
	if (dir == 0)return x - 1;
	if (dir == 1)return n - x;
	if (dir == 2)return y - 1;
	if (dir == 3)return m - y;
}
long long Get(int x, int y, int dir) {
	long long tp = Num(x, y, dir);
	if (Map.count(tp))return Map[tp];
	if (x == 2 && y == 2 && dir == 1) {
		int ck = -1;
	}
	int t;
	if (dir == 0) t = IT[0].Before(x, Y[y]);
	if (dir == 1) t = IT[0].Next(x, Y[y]);
	if (dir == 2) t = IT[1].Before(y, X[x]);
	if (dir == 3) t = IT[1].Next(y, X[x]);
	long long Mn = 0;
	if (t<1 || t>1e6) {
		Map[tp] = Calc(x, y, dir);
		return Map[tp];
	}
	if (dir == 0 || dir == 1) {
		Mn = max(Mn, Get(t, y, 2) + abs(t - x));
		Mn = max(Mn, Get(t, y, 3) + abs(t - x));
	}
	else {
		Mn = max(Mn, Get(x, t, 0) + abs(t - y));
		Mn = max(Mn, Get(x, t, 1) + abs(t - y));
	}
	Map[tp] = Mn;
	return Mn;
}
int main() {
	int i, x, y;
	scanf("%d%d%d", &n, &m, &Q);
	for (i = 1; i <= n; i++) {
		scanf("%d", &X[i]);
		IT[0].Put(i, X[i]);
	}
	for (i = 1; i <= m; i++) {
		scanf("%d", &Y[i]);
		IT[1].Put(i, Y[i]);
	}
	while (Q--) {
		scanf("%d%d", &x, &y);
		long long Mn = 0;
		for (i = 0; i < 4; i++) {
			Mn = max(Mn, Get(x, y, i));
		}
		printf("%lld\n", Mn);
	}
}

Compilation message

abduction2.cpp: In function 'long long int Get(int, int, int)':
abduction2.cpp:67:7: warning: unused variable 'ck' [-Wunused-variable]
   int ck = -1;
       ^~
abduction2.cpp: In function 'int Calc(int, int, int)':
abduction2.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
abduction2.cpp: In function 'int main()':
abduction2.cpp:92: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:94:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &X[i]);
   ~~~~~^~~~~~~~~~~~~
abduction2.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &Y[i]);
   ~~~~~^~~~~~~~~~~~~
abduction2.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~
abduction2.cpp: In function 'long long int Get(int, int, int)':
abduction2.cpp:75:2: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (t<1 || t>1e6) {
  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 544 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 4 ms 544 KB Output is correct
5 Correct 1 ms 544 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 544 KB Output is correct
9 Correct 3 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 3 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 544 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 4 ms 544 KB Output is correct
5 Correct 1 ms 544 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 544 KB Output is correct
9 Correct 3 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 3 ms 544 KB Output is correct
12 Correct 4 ms 544 KB Output is correct
13 Correct 4 ms 552 KB Output is correct
14 Correct 6 ms 576 KB Output is correct
15 Correct 4 ms 576 KB Output is correct
16 Correct 5 ms 576 KB Output is correct
17 Correct 5 ms 576 KB Output is correct
18 Correct 5 ms 704 KB Output is correct
19 Correct 8 ms 1068 KB Output is correct
20 Correct 10 ms 1344 KB Output is correct
21 Correct 6 ms 1344 KB Output is correct
22 Correct 11 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 544 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 4 ms 544 KB Output is correct
5 Correct 1 ms 544 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 544 KB Output is correct
9 Correct 3 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 3 ms 544 KB Output is correct
12 Correct 4 ms 544 KB Output is correct
13 Correct 4 ms 552 KB Output is correct
14 Correct 6 ms 576 KB Output is correct
15 Correct 4 ms 576 KB Output is correct
16 Correct 5 ms 576 KB Output is correct
17 Correct 5 ms 576 KB Output is correct
18 Correct 5 ms 704 KB Output is correct
19 Correct 8 ms 1068 KB Output is correct
20 Correct 10 ms 1344 KB Output is correct
21 Correct 6 ms 1344 KB Output is correct
22 Correct 11 ms 1516 KB Output is correct
23 Correct 29 ms 1772 KB Output is correct
24 Correct 33 ms 1772 KB Output is correct
25 Correct 34 ms 1772 KB Output is correct
26 Correct 41 ms 1772 KB Output is correct
27 Correct 33 ms 1772 KB Output is correct
28 Correct 89 ms 7940 KB Output is correct
29 Correct 42 ms 7940 KB Output is correct
30 Correct 162 ms 12352 KB Output is correct
31 Correct 160 ms 15340 KB Output is correct
32 Correct 48 ms 15340 KB Output is correct
33 Correct 68 ms 15340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15340 KB Output is correct
2 Correct 7 ms 15340 KB Output is correct
3 Correct 6 ms 15340 KB Output is correct
4 Correct 9 ms 15340 KB Output is correct
5 Correct 7 ms 15340 KB Output is correct
6 Correct 6 ms 15340 KB Output is correct
7 Correct 7 ms 15340 KB Output is correct
8 Correct 15 ms 15340 KB Output is correct
9 Correct 11 ms 15340 KB Output is correct
10 Correct 10 ms 15340 KB Output is correct
11 Correct 12 ms 15340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 544 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 4 ms 544 KB Output is correct
5 Correct 1 ms 544 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 544 KB Output is correct
9 Correct 3 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 3 ms 544 KB Output is correct
12 Correct 4 ms 544 KB Output is correct
13 Correct 4 ms 552 KB Output is correct
14 Correct 6 ms 576 KB Output is correct
15 Correct 4 ms 576 KB Output is correct
16 Correct 5 ms 576 KB Output is correct
17 Correct 5 ms 576 KB Output is correct
18 Correct 5 ms 704 KB Output is correct
19 Correct 8 ms 1068 KB Output is correct
20 Correct 10 ms 1344 KB Output is correct
21 Correct 6 ms 1344 KB Output is correct
22 Correct 11 ms 1516 KB Output is correct
23 Correct 29 ms 1772 KB Output is correct
24 Correct 33 ms 1772 KB Output is correct
25 Correct 34 ms 1772 KB Output is correct
26 Correct 41 ms 1772 KB Output is correct
27 Correct 33 ms 1772 KB Output is correct
28 Correct 89 ms 7940 KB Output is correct
29 Correct 42 ms 7940 KB Output is correct
30 Correct 162 ms 12352 KB Output is correct
31 Correct 160 ms 15340 KB Output is correct
32 Correct 48 ms 15340 KB Output is correct
33 Correct 68 ms 15340 KB Output is correct
34 Correct 9 ms 15340 KB Output is correct
35 Correct 7 ms 15340 KB Output is correct
36 Correct 6 ms 15340 KB Output is correct
37 Correct 9 ms 15340 KB Output is correct
38 Correct 7 ms 15340 KB Output is correct
39 Correct 6 ms 15340 KB Output is correct
40 Correct 7 ms 15340 KB Output is correct
41 Correct 15 ms 15340 KB Output is correct
42 Correct 11 ms 15340 KB Output is correct
43 Correct 10 ms 15340 KB Output is correct
44 Correct 12 ms 15340 KB Output is correct
45 Correct 36 ms 15340 KB Output is correct
46 Correct 36 ms 15340 KB Output is correct
47 Correct 34 ms 15340 KB Output is correct
48 Correct 38 ms 15340 KB Output is correct
49 Correct 38 ms 15340 KB Output is correct
50 Correct 78 ms 15340 KB Output is correct
51 Correct 77 ms 15340 KB Output is correct
52 Correct 261 ms 20860 KB Output is correct
53 Correct 227 ms 20860 KB Output is correct
54 Correct 240 ms 20860 KB Output is correct
55 Correct 458 ms 28156 KB Output is correct
56 Correct 4181 ms 252144 KB Output is correct
57 Correct 823 ms 252144 KB Output is correct
58 Correct 766 ms 252144 KB Output is correct
59 Correct 867 ms 252144 KB Output is correct