답안 #336796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336796 2020-12-16T20:39:21 Z super_j6 유괴 2 (JOI17_abduction2) C++14
100 / 100
1032 ms 101608 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
 
typedef array<int, 2> T;
T operator+(T x, T y){ return {x[0] + y[0], x[1] + y[1]};}
T operator*(int x, T y){ return {x * y[0], x * y[1]};}
 
const int mxn = 50000, m = __lg(mxn - 1) + 1, k = 4;
const T d[k] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n[2], q;
int a[2][m][mxn];
unordered_map<int, ll> dp[k][mxn];
 
ll sol(T x, int y){
	ll ret = 0, s = 0;
	for(int i = m - 1; ~i; i--){
		T p = x + (1 << i) * d[y];
		if(p[y & 1] >= -1 && p[y & 1] <= n[y & 1] && a[!(y & 1)][0][p[!(y & 1)]] > 
		a[y & 1][i][y & 2 ? p[y & 1] + 1 : x[y & 1]]){
			x = p, s += (1 << i);
		}
	}
	if(!~x[y & 1] || x[y & 1] == n[y & 1]) return s;
	if(dp[y][x[0]].count(x[1])) return dp[y][x[0]][x[1]] + s;
	for(int i = 0; i < 2; i++){
		int z = (y + 2 * i + 1) % k;
		ret = max(ret, sol(x + d[z], z));
	}
	dp[y][x[0]][x[1]] = ++ret;
	return ret + s;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n[0] >> n[1] >> q;
	
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < n[i]; j++){
			cin >> a[i][0][j];
		}
		for(int j = 1; j < m; j++)
		for(int l = 0; l + (1 << j) <= n[i]; l++){
			a[i][j][l] = max(a[i][j - 1][l], a[i][j - 1][l + (1 << (j - 1))]);
		}
	}
	
	while(q--){
		T x;
		for(int i = 0; i < 2; i++) cin >> x[i], x[i]--;
		ll ret = 0;
		for(int i = 0; i < k; i++) ret = max(ret, sol(x + d[i], i));
		cout << ret << endl;
	}
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11372 KB Output is correct
2 Correct 8 ms 11372 KB Output is correct
3 Correct 11 ms 11372 KB Output is correct
4 Correct 8 ms 11372 KB Output is correct
5 Correct 8 ms 11372 KB Output is correct
6 Correct 9 ms 11372 KB Output is correct
7 Correct 8 ms 11372 KB Output is correct
8 Correct 8 ms 11372 KB Output is correct
9 Correct 8 ms 11372 KB Output is correct
10 Correct 8 ms 11372 KB Output is correct
11 Correct 10 ms 11372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11372 KB Output is correct
2 Correct 8 ms 11372 KB Output is correct
3 Correct 11 ms 11372 KB Output is correct
4 Correct 8 ms 11372 KB Output is correct
5 Correct 8 ms 11372 KB Output is correct
6 Correct 9 ms 11372 KB Output is correct
7 Correct 8 ms 11372 KB Output is correct
8 Correct 8 ms 11372 KB Output is correct
9 Correct 8 ms 11372 KB Output is correct
10 Correct 8 ms 11372 KB Output is correct
11 Correct 10 ms 11372 KB Output is correct
12 Correct 11 ms 11500 KB Output is correct
13 Correct 9 ms 11500 KB Output is correct
14 Correct 9 ms 11520 KB Output is correct
15 Correct 9 ms 11500 KB Output is correct
16 Correct 9 ms 11500 KB Output is correct
17 Correct 9 ms 11500 KB Output is correct
18 Correct 9 ms 11628 KB Output is correct
19 Correct 10 ms 11756 KB Output is correct
20 Correct 11 ms 11884 KB Output is correct
21 Correct 10 ms 11756 KB Output is correct
22 Correct 12 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11372 KB Output is correct
2 Correct 8 ms 11372 KB Output is correct
3 Correct 11 ms 11372 KB Output is correct
4 Correct 8 ms 11372 KB Output is correct
5 Correct 8 ms 11372 KB Output is correct
6 Correct 9 ms 11372 KB Output is correct
7 Correct 8 ms 11372 KB Output is correct
8 Correct 8 ms 11372 KB Output is correct
9 Correct 8 ms 11372 KB Output is correct
10 Correct 8 ms 11372 KB Output is correct
11 Correct 10 ms 11372 KB Output is correct
12 Correct 11 ms 11500 KB Output is correct
13 Correct 9 ms 11500 KB Output is correct
14 Correct 9 ms 11520 KB Output is correct
15 Correct 9 ms 11500 KB Output is correct
16 Correct 9 ms 11500 KB Output is correct
17 Correct 9 ms 11500 KB Output is correct
18 Correct 9 ms 11628 KB Output is correct
19 Correct 10 ms 11756 KB Output is correct
20 Correct 11 ms 11884 KB Output is correct
21 Correct 10 ms 11756 KB Output is correct
22 Correct 12 ms 12140 KB Output is correct
23 Correct 24 ms 17132 KB Output is correct
24 Correct 24 ms 17132 KB Output is correct
25 Correct 24 ms 17132 KB Output is correct
26 Correct 27 ms 17260 KB Output is correct
27 Correct 24 ms 17132 KB Output is correct
28 Correct 50 ms 22252 KB Output is correct
29 Correct 26 ms 17772 KB Output is correct
30 Correct 68 ms 23148 KB Output is correct
31 Correct 84 ms 24812 KB Output is correct
32 Correct 27 ms 17516 KB Output is correct
33 Correct 35 ms 19436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 11628 KB Output is correct
2 Correct 11 ms 11628 KB Output is correct
3 Correct 11 ms 11628 KB Output is correct
4 Correct 11 ms 11628 KB Output is correct
5 Correct 10 ms 11628 KB Output is correct
6 Correct 14 ms 11756 KB Output is correct
7 Correct 10 ms 11756 KB Output is correct
8 Correct 12 ms 12012 KB Output is correct
9 Correct 13 ms 12012 KB Output is correct
10 Correct 12 ms 11884 KB Output is correct
11 Correct 12 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11372 KB Output is correct
2 Correct 8 ms 11372 KB Output is correct
3 Correct 11 ms 11372 KB Output is correct
4 Correct 8 ms 11372 KB Output is correct
5 Correct 8 ms 11372 KB Output is correct
6 Correct 9 ms 11372 KB Output is correct
7 Correct 8 ms 11372 KB Output is correct
8 Correct 8 ms 11372 KB Output is correct
9 Correct 8 ms 11372 KB Output is correct
10 Correct 8 ms 11372 KB Output is correct
11 Correct 10 ms 11372 KB Output is correct
12 Correct 11 ms 11500 KB Output is correct
13 Correct 9 ms 11500 KB Output is correct
14 Correct 9 ms 11520 KB Output is correct
15 Correct 9 ms 11500 KB Output is correct
16 Correct 9 ms 11500 KB Output is correct
17 Correct 9 ms 11500 KB Output is correct
18 Correct 9 ms 11628 KB Output is correct
19 Correct 10 ms 11756 KB Output is correct
20 Correct 11 ms 11884 KB Output is correct
21 Correct 10 ms 11756 KB Output is correct
22 Correct 12 ms 12140 KB Output is correct
23 Correct 24 ms 17132 KB Output is correct
24 Correct 24 ms 17132 KB Output is correct
25 Correct 24 ms 17132 KB Output is correct
26 Correct 27 ms 17260 KB Output is correct
27 Correct 24 ms 17132 KB Output is correct
28 Correct 50 ms 22252 KB Output is correct
29 Correct 26 ms 17772 KB Output is correct
30 Correct 68 ms 23148 KB Output is correct
31 Correct 84 ms 24812 KB Output is correct
32 Correct 27 ms 17516 KB Output is correct
33 Correct 35 ms 19436 KB Output is correct
34 Correct 13 ms 11628 KB Output is correct
35 Correct 11 ms 11628 KB Output is correct
36 Correct 11 ms 11628 KB Output is correct
37 Correct 11 ms 11628 KB Output is correct
38 Correct 10 ms 11628 KB Output is correct
39 Correct 14 ms 11756 KB Output is correct
40 Correct 10 ms 11756 KB Output is correct
41 Correct 12 ms 12012 KB Output is correct
42 Correct 13 ms 12012 KB Output is correct
43 Correct 12 ms 11884 KB Output is correct
44 Correct 12 ms 12012 KB Output is correct
45 Correct 27 ms 17388 KB Output is correct
46 Correct 27 ms 17388 KB Output is correct
47 Correct 28 ms 17388 KB Output is correct
48 Correct 27 ms 17536 KB Output is correct
49 Correct 27 ms 17388 KB Output is correct
50 Correct 45 ms 21612 KB Output is correct
51 Correct 46 ms 22252 KB Output is correct
52 Correct 113 ms 26732 KB Output is correct
53 Correct 110 ms 26220 KB Output is correct
54 Correct 102 ms 25836 KB Output is correct
55 Correct 127 ms 32108 KB Output is correct
56 Correct 1032 ms 101608 KB Output is correct
57 Correct 281 ms 41708 KB Output is correct
58 Correct 263 ms 40556 KB Output is correct
59 Correct 264 ms 40940 KB Output is correct