답안 #1031910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031910 2024-07-23T08:39:05 Z 정민찬(#10962) Golf (JOI17_golf) C++17
30 / 100
955 ms 558820 KB
#include <bits/stdc++.h>

using namespace std;

int board[5010][5010];
int dist[5010][5010][4];
int vis[5010][5010][4];

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	int s, t, u, v;
	cin >> s >> t >> u >> v;
	int n;
	cin >> n;
	vector<array<int,4>> a(n);
	vector<int> X = {s, u}, Y = {t, v};
	for (int i=0; i<n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
		X.push_back(a[i][0]);
		X.push_back(a[i][1]);
		Y.push_back(a[i][2]);
		Y.push_back(a[i][3]);
	}
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());
	sort(Y.begin(), Y.end());
	Y.erase(unique(Y.begin(), Y.end()), Y.end());
	for (int i=0; i<n; i++) {
		a[i][0] = lower_bound(X.begin(), X.end(), a[i][0]) - X.begin() + 1;
		a[i][1] = lower_bound(X.begin(), X.end(), a[i][1]) - X.begin() + 1;
		a[i][2] = lower_bound(Y.begin(), Y.end(), a[i][2]) - Y.begin() + 1;
		a[i][3] = lower_bound(Y.begin(), Y.end(), a[i][3]) - Y.begin() + 1;
	}
	s = lower_bound(X.begin(), X.end(), s) - X.begin() + 1;
	u = lower_bound(X.begin(), X.end(), u) - X.begin() + 1;
	t = lower_bound(Y.begin(), Y.end(), t) - Y.begin() + 1;
	v = lower_bound(Y.begin(), Y.end(), v) - Y.begin() + 1;
	s *= 2; u *= 2; t *= 2; v *= 2;
	for (int i=0; i<n; i++) {
		for (int x=a[i][0]*2+1; x<=a[i][1]*2-1; x++) {
			for (int y=a[i][2]*2+1; y<=a[i][3]*2-1; y++) {
				board[x][y] = 1;
			}
		}
	}
	int mX = X.size() * 2 + 2;
	int mY = Y.size() * 2 + 2;
	deque<array<int,4>> dq;
	for (int i=0; i<4; i++) {
		dq.push_back({s, t, i, 1});
		dist[s][t][i] = 0;
	}
	while (!dq.empty()) {
		int x = dq.front()[0];
		int y = dq.front()[1];
		int dir = dq.front()[2];
		int cost = dq.front()[3];
		dq.pop_front();
		if (vis[x][y][dir]) continue;
		vis[x][y][dir] = 1;
		if (x == u && y == v) {
			cout << cost << '\n';
			break;
		}
		for (int k=0; k<4; k++) {
			int nx = x + dx[k];
			int ny = y + dy[k];
			if (nx < 0 || nx > mX || ny < 0 || ny > mY) continue;
			if (board[nx][ny]) continue;
			if (k == dir) {
				dq.push_front({nx, ny, k, cost});
			}
			else {
				dq.push_back({nx, ny, k, cost+1});
			}
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 3 ms 5620 KB Output is correct
5 Correct 134 ms 108360 KB Output is correct
6 Correct 82 ms 83404 KB Output is correct
7 Correct 141 ms 92172 KB Output is correct
8 Correct 131 ms 96304 KB Output is correct
9 Correct 135 ms 87060 KB Output is correct
10 Correct 62 ms 61572 KB Output is correct
11 Correct 61 ms 75332 KB Output is correct
12 Correct 43 ms 49488 KB Output is correct
13 Correct 136 ms 90388 KB Output is correct
14 Correct 128 ms 88880 KB Output is correct
15 Correct 64 ms 20564 KB Output is correct
16 Correct 257 ms 60444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 3 ms 5620 KB Output is correct
5 Correct 134 ms 108360 KB Output is correct
6 Correct 82 ms 83404 KB Output is correct
7 Correct 141 ms 92172 KB Output is correct
8 Correct 131 ms 96304 KB Output is correct
9 Correct 135 ms 87060 KB Output is correct
10 Correct 62 ms 61572 KB Output is correct
11 Correct 61 ms 75332 KB Output is correct
12 Correct 43 ms 49488 KB Output is correct
13 Correct 136 ms 90388 KB Output is correct
14 Correct 128 ms 88880 KB Output is correct
15 Correct 64 ms 20564 KB Output is correct
16 Correct 257 ms 60444 KB Output is correct
17 Correct 680 ms 485724 KB Output is correct
18 Correct 686 ms 524776 KB Output is correct
19 Correct 466 ms 357016 KB Output is correct
20 Correct 795 ms 496492 KB Output is correct
21 Correct 908 ms 558820 KB Output is correct
22 Correct 388 ms 356180 KB Output is correct
23 Correct 290 ms 269524 KB Output is correct
24 Correct 955 ms 469740 KB Output is correct
25 Correct 182 ms 216228 KB Output is correct
26 Correct 751 ms 433404 KB Output is correct
27 Correct 91 ms 27176 KB Output is correct
28 Correct 308 ms 71056 KB Output is correct
29 Correct 351 ms 72968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 3 ms 5620 KB Output is correct
5 Correct 134 ms 108360 KB Output is correct
6 Correct 82 ms 83404 KB Output is correct
7 Correct 141 ms 92172 KB Output is correct
8 Correct 131 ms 96304 KB Output is correct
9 Correct 135 ms 87060 KB Output is correct
10 Correct 62 ms 61572 KB Output is correct
11 Correct 61 ms 75332 KB Output is correct
12 Correct 43 ms 49488 KB Output is correct
13 Correct 136 ms 90388 KB Output is correct
14 Correct 128 ms 88880 KB Output is correct
15 Correct 64 ms 20564 KB Output is correct
16 Correct 257 ms 60444 KB Output is correct
17 Correct 680 ms 485724 KB Output is correct
18 Correct 686 ms 524776 KB Output is correct
19 Correct 466 ms 357016 KB Output is correct
20 Correct 795 ms 496492 KB Output is correct
21 Correct 908 ms 558820 KB Output is correct
22 Correct 388 ms 356180 KB Output is correct
23 Correct 290 ms 269524 KB Output is correct
24 Correct 955 ms 469740 KB Output is correct
25 Correct 182 ms 216228 KB Output is correct
26 Correct 751 ms 433404 KB Output is correct
27 Correct 91 ms 27176 KB Output is correct
28 Correct 308 ms 71056 KB Output is correct
29 Correct 351 ms 72968 KB Output is correct
30 Runtime error 653 ms 105272 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -