답안 #714838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714838 2023-03-25T10:19:17 Z Sohsoh84 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
833 ms 230440 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 4e3 + 10;
const int DX[4] = {0, -1, 0, 1};
const int DY[4] = {-1, 0, 1, 0};

int state[MAXN][MAXN], n, m, dist[MAXN][MAXN];
deque<pll> dq;

inline void update(int i, int j, int d, int td) {
	if (!state[i][j]) return;
	if (d + td < dist[i][j]) {
		dist[i][j] = d + td;
		if (td == 0) dq.push_front({i, j});
		else dq.push_back({i, j});
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			if (c == 'F') state[i][j] = 1;
			else if (c == 'R') state[i][j] = 2;
		}
	}

	memset(dist, 63, sizeof dist);
	dq.push_back({1, 1});
	dist[1][1] = 0;

	while (!dq.empty()) {
		auto [x, y] = dq.front();
		dq.pop_front();

		int d = dist[x][y];
		for (int f = 0; f < 4; f++) {
			int tx = x + DX[f], ty = y + DY[f];
			update(tx, ty, d, int(state[x][y] != state[tx][ty]));
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (state[i][j])
				ans = max(ans, dist[i][j]);
	
	cout << ans + 1 << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 66404 KB Output is correct
2 Correct 26 ms 63308 KB Output is correct
3 Correct 28 ms 63372 KB Output is correct
4 Correct 33 ms 66508 KB Output is correct
5 Correct 29 ms 64688 KB Output is correct
6 Correct 24 ms 63280 KB Output is correct
7 Correct 25 ms 63392 KB Output is correct
8 Correct 25 ms 63456 KB Output is correct
9 Correct 25 ms 63592 KB Output is correct
10 Correct 29 ms 64412 KB Output is correct
11 Correct 26 ms 64312 KB Output is correct
12 Correct 30 ms 64780 KB Output is correct
13 Correct 28 ms 64720 KB Output is correct
14 Correct 28 ms 64724 KB Output is correct
15 Correct 37 ms 66300 KB Output is correct
16 Correct 41 ms 66520 KB Output is correct
17 Correct 39 ms 66232 KB Output is correct
18 Correct 33 ms 66396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 78756 KB Output is correct
2 Correct 79 ms 73160 KB Output is correct
3 Correct 395 ms 120856 KB Output is correct
4 Correct 126 ms 88260 KB Output is correct
5 Correct 306 ms 104580 KB Output is correct
6 Correct 829 ms 170744 KB Output is correct
7 Correct 31 ms 79436 KB Output is correct
8 Correct 30 ms 78804 KB Output is correct
9 Correct 25 ms 63564 KB Output is correct
10 Correct 24 ms 63288 KB Output is correct
11 Correct 30 ms 79124 KB Output is correct
12 Correct 26 ms 63864 KB Output is correct
13 Correct 77 ms 73164 KB Output is correct
14 Correct 61 ms 69780 KB Output is correct
15 Correct 66 ms 72008 KB Output is correct
16 Correct 62 ms 67020 KB Output is correct
17 Correct 168 ms 83956 KB Output is correct
18 Correct 147 ms 90704 KB Output is correct
19 Correct 148 ms 88336 KB Output is correct
20 Correct 113 ms 81612 KB Output is correct
21 Correct 246 ms 103372 KB Output is correct
22 Correct 256 ms 104608 KB Output is correct
23 Correct 307 ms 96860 KB Output is correct
24 Correct 238 ms 100556 KB Output is correct
25 Correct 663 ms 141644 KB Output is correct
26 Correct 651 ms 230440 KB Output is correct
27 Correct 722 ms 200516 KB Output is correct
28 Correct 833 ms 170848 KB Output is correct
29 Correct 827 ms 165760 KB Output is correct
30 Correct 784 ms 173264 KB Output is correct
31 Correct 609 ms 124344 KB Output is correct
32 Correct 723 ms 186600 KB Output is correct