답안 #336791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336791 2020-12-16T20:11:09 Z super_j6 유괴 2 (JOI17_abduction2) C++14
27 / 100
5000 ms 17548 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]};
}
 
const int mxn = 50000, k = 4;
const T d[k] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n[2], q;
int a[2][mxn];
unordered_map<int, int> dp[k][mxn];

inline bool f(T x){
	return x[0] >= 0 && x[0] < n[0] && x[1] >= 0 && x[1] < n[1];
}
 
int sol(T x, int y){
	int ret = 0, s = 0;
	for(; f(x) && a[!(y & 1)][x[!(y & 1)]] > a[y & 1][x[y & 1]]; x = x + d[y]) s++;
	if(!f(x)) 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][j];
	}
	
	while(q--){
		T x;
		for(int i = 0; i < 2; i++) cin >> x[i], x[i]--;
		int 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 11244 KB Output is correct
2 Correct 8 ms 11244 KB Output is correct
3 Correct 9 ms 11244 KB Output is correct
4 Correct 8 ms 11244 KB Output is correct
5 Correct 8 ms 11244 KB Output is correct
6 Correct 8 ms 11244 KB Output is correct
7 Correct 8 ms 11244 KB Output is correct
8 Correct 8 ms 11244 KB Output is correct
9 Correct 9 ms 11244 KB Output is correct
10 Correct 9 ms 11244 KB Output is correct
11 Correct 8 ms 11244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11244 KB Output is correct
2 Correct 8 ms 11244 KB Output is correct
3 Correct 9 ms 11244 KB Output is correct
4 Correct 8 ms 11244 KB Output is correct
5 Correct 8 ms 11244 KB Output is correct
6 Correct 8 ms 11244 KB Output is correct
7 Correct 8 ms 11244 KB Output is correct
8 Correct 8 ms 11244 KB Output is correct
9 Correct 9 ms 11244 KB Output is correct
10 Correct 9 ms 11244 KB Output is correct
11 Correct 8 ms 11244 KB Output is correct
12 Correct 9 ms 11372 KB Output is correct
13 Correct 9 ms 11372 KB Output is correct
14 Correct 9 ms 11372 KB Output is correct
15 Correct 9 ms 11372 KB Output is correct
16 Correct 9 ms 11372 KB Output is correct
17 Correct 9 ms 11372 KB Output is correct
18 Correct 10 ms 11372 KB Output is correct
19 Correct 19 ms 11500 KB Output is correct
20 Correct 23 ms 11628 KB Output is correct
21 Correct 21 ms 11500 KB Output is correct
22 Correct 29 ms 11884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11244 KB Output is correct
2 Correct 8 ms 11244 KB Output is correct
3 Correct 9 ms 11244 KB Output is correct
4 Correct 8 ms 11244 KB Output is correct
5 Correct 8 ms 11244 KB Output is correct
6 Correct 8 ms 11244 KB Output is correct
7 Correct 8 ms 11244 KB Output is correct
8 Correct 8 ms 11244 KB Output is correct
9 Correct 9 ms 11244 KB Output is correct
10 Correct 9 ms 11244 KB Output is correct
11 Correct 8 ms 11244 KB Output is correct
12 Correct 9 ms 11372 KB Output is correct
13 Correct 9 ms 11372 KB Output is correct
14 Correct 9 ms 11372 KB Output is correct
15 Correct 9 ms 11372 KB Output is correct
16 Correct 9 ms 11372 KB Output is correct
17 Correct 9 ms 11372 KB Output is correct
18 Correct 10 ms 11372 KB Output is correct
19 Correct 19 ms 11500 KB Output is correct
20 Correct 23 ms 11628 KB Output is correct
21 Correct 21 ms 11500 KB Output is correct
22 Correct 29 ms 11884 KB Output is correct
23 Correct 22 ms 11628 KB Output is correct
24 Correct 21 ms 11628 KB Output is correct
25 Correct 21 ms 11628 KB Output is correct
26 Correct 21 ms 11628 KB Output is correct
27 Correct 20 ms 11756 KB Output is correct
28 Correct 2811 ms 17548 KB Output is correct
29 Correct 598 ms 12760 KB Output is correct
30 Execution timed out 5069 ms 15956 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 11500 KB Output is correct
2 Correct 11 ms 11500 KB Output is correct
3 Correct 11 ms 11500 KB Output is correct
4 Correct 11 ms 11500 KB Output is correct
5 Correct 11 ms 11500 KB Output is correct
6 Correct 16 ms 11628 KB Output is correct
7 Correct 18 ms 11500 KB Output is correct
8 Correct 33 ms 11756 KB Output is correct
9 Correct 27 ms 11756 KB Output is correct
10 Correct 27 ms 11756 KB Output is correct
11 Correct 32 ms 11884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11244 KB Output is correct
2 Correct 8 ms 11244 KB Output is correct
3 Correct 9 ms 11244 KB Output is correct
4 Correct 8 ms 11244 KB Output is correct
5 Correct 8 ms 11244 KB Output is correct
6 Correct 8 ms 11244 KB Output is correct
7 Correct 8 ms 11244 KB Output is correct
8 Correct 8 ms 11244 KB Output is correct
9 Correct 9 ms 11244 KB Output is correct
10 Correct 9 ms 11244 KB Output is correct
11 Correct 8 ms 11244 KB Output is correct
12 Correct 9 ms 11372 KB Output is correct
13 Correct 9 ms 11372 KB Output is correct
14 Correct 9 ms 11372 KB Output is correct
15 Correct 9 ms 11372 KB Output is correct
16 Correct 9 ms 11372 KB Output is correct
17 Correct 9 ms 11372 KB Output is correct
18 Correct 10 ms 11372 KB Output is correct
19 Correct 19 ms 11500 KB Output is correct
20 Correct 23 ms 11628 KB Output is correct
21 Correct 21 ms 11500 KB Output is correct
22 Correct 29 ms 11884 KB Output is correct
23 Correct 22 ms 11628 KB Output is correct
24 Correct 21 ms 11628 KB Output is correct
25 Correct 21 ms 11628 KB Output is correct
26 Correct 21 ms 11628 KB Output is correct
27 Correct 20 ms 11756 KB Output is correct
28 Correct 2811 ms 17548 KB Output is correct
29 Correct 598 ms 12760 KB Output is correct
30 Execution timed out 5069 ms 15956 KB Time limit exceeded
31 Halted 0 ms 0 KB -