답안 #282292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282292 2020-08-24T08:54:42 Z 임성재(#5755) 유괴 2 (JOI17_abduction2) C++17
13 / 100
5000 ms 33572 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9 + 7;
const ll INF = 1e18;

int n, m, q;
int a[50010];
int b[50010];
vector<pii> v;
int ans[2][2010][2010];
bool chk[100010];

int main() {
	fast;

	cin >> n >> m >> q;

	for(int i=1; i<=n; i++) {
		cin >> a[i];

		v.eb(a[i], i);
	}

	for(int i=1; i<=m; i++) {
		cin >> b[i];

		v.eb(b[i], i+n);
	}

	while(q--) {
		int x, y;
		cin >> x >> y;

		priority_queue<pii, vector<pii>, greater<pii>> pq;

		int ans = 0;
		pq.em(0, x + y * n);

		while(pq.size()) {
			int cost = pq.top().fi;
			int X = (pq.top().se - 1) % n + 1;
			int Y = (pq.top().se - 1) / n;

			pq.pop();

			ans = max(ans, cost);

			if(a[X] > b[Y] || (x == X && y == Y)) {
				for(int i=Y+1; i<=m; i++) {
					if(b[i] > a[X]) {
						pq.em(cost + i - Y, X + i * n);
						break;
					}
					if(i == m) ans = max(ans, cost + i - Y);
				}

				for(int i=Y-1; i>=1; i--) {
					if(b[i] > a[X]) {
						pq.em(cost + Y - i, X + i * n);
						break;
					}
					if(i == 1) ans = max(ans, cost + Y - i);
				}
			}
			if(a[X] < b[Y] || (x == X && y == Y)) {
				for(int i=X+1; i<=n; i++) {
					if(a[i] > b[Y]) {
						pq.em(cost + i - X, i + Y * n);
						break;
					}
					if(i == n) ans = max(ans, cost + i - X);
				}
				for(int i=X-1; i>=1; i--) {
					if(a[i] > b[Y]) {
						pq.em(cost + X - i, i + Y * n);
						break;
					}
					if(i == 1) ans = max(ans, cost + X - i);
				}
			}
		}
		
		cout << ans << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Execution timed out 5104 ms 33572 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Execution timed out 5104 ms 33572 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 348 ms 632 KB Output is correct
2 Correct 184 ms 512 KB Output is correct
3 Correct 281 ms 684 KB Output is correct
4 Correct 293 ms 760 KB Output is correct
5 Correct 410 ms 888 KB Output is correct
6 Correct 274 ms 632 KB Output is correct
7 Correct 259 ms 516 KB Output is correct
8 Execution timed out 5094 ms 33384 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Execution timed out 5104 ms 33572 KB Time limit exceeded
20 Halted 0 ms 0 KB -