답안 #256286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256286 2020-08-02T13:45:42 Z Saboon Tracks in the Snow (BOI13_tracks) C++14
100 / 100
694 ms 129028 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int maxn = 4000 + 10;

int h[maxn][maxn];
string s[maxn];

int adjx[] = {0, -1, 0, 1};
int adjy[] = {1, 0, -1, 0};

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> s[i];
	deque<pair<int,int>> deQ;
	memset(h, -1, sizeof h);
	h[0][0] = 1;
	deQ.push_back({0,0});
	int answer = 0;
	while (!deQ.empty()){
		auto it = deQ.front();
		deQ.pop_front();
		int x = it.first, y = it.second;
		answer = max(answer, h[x][y]);
		for (int z = 0; z < 4; z++){
			int nx = x + adjx[z], ny = y + adjy[z];
			if (0 <= nx and nx < n and 0 <= ny and ny < m and s[nx][ny] != '.'){
				int w = (s[nx][ny] != s[x][y]);
				if (h[nx][ny] != -1 and h[nx][ny] <= h[x][y] + 1)
					continue;
				h[nx][ny] = h[x][y] + w;
				if (w == 0)
					deQ.push_front({nx,ny});
				else
					deQ.push_back({nx,ny});
			}
		}
	}
	cout << answer << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 63864 KB Output is correct
2 Correct 39 ms 63352 KB Output is correct
3 Correct 39 ms 63480 KB Output is correct
4 Correct 38 ms 63864 KB Output is correct
5 Correct 35 ms 63608 KB Output is correct
6 Correct 37 ms 63352 KB Output is correct
7 Correct 34 ms 63352 KB Output is correct
8 Correct 39 ms 63352 KB Output is correct
9 Correct 34 ms 63356 KB Output is correct
10 Correct 34 ms 63480 KB Output is correct
11 Correct 35 ms 63480 KB Output is correct
12 Correct 37 ms 63608 KB Output is correct
13 Correct 36 ms 63608 KB Output is correct
14 Correct 35 ms 63608 KB Output is correct
15 Correct 41 ms 63864 KB Output is correct
16 Correct 44 ms 63896 KB Output is correct
17 Correct 40 ms 63864 KB Output is correct
18 Correct 39 ms 63904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 63480 KB Output is correct
2 Correct 81 ms 66600 KB Output is correct
3 Correct 187 ms 83320 KB Output is correct
4 Correct 83 ms 69496 KB Output is correct
5 Correct 161 ms 75384 KB Output is correct
6 Correct 609 ms 96664 KB Output is correct
7 Correct 39 ms 63480 KB Output is correct
8 Correct 40 ms 63488 KB Output is correct
9 Correct 39 ms 63608 KB Output is correct
10 Correct 36 ms 63540 KB Output is correct
11 Correct 37 ms 63480 KB Output is correct
12 Correct 40 ms 63480 KB Output is correct
13 Correct 69 ms 66552 KB Output is correct
14 Correct 53 ms 65144 KB Output is correct
15 Correct 47 ms 65400 KB Output is correct
16 Correct 49 ms 64760 KB Output is correct
17 Correct 117 ms 69880 KB Output is correct
18 Correct 96 ms 69848 KB Output is correct
19 Correct 80 ms 69496 KB Output is correct
20 Correct 70 ms 69248 KB Output is correct
21 Correct 124 ms 75512 KB Output is correct
22 Correct 160 ms 75256 KB Output is correct
23 Correct 199 ms 73976 KB Output is correct
24 Correct 128 ms 75256 KB Output is correct
25 Correct 382 ms 83320 KB Output is correct
26 Correct 694 ms 129028 KB Output is correct
27 Correct 602 ms 113272 KB Output is correct
28 Correct 687 ms 96860 KB Output is correct
29 Correct 609 ms 94968 KB Output is correct
30 Correct 640 ms 101040 KB Output is correct
31 Correct 519 ms 77176 KB Output is correct
32 Correct 634 ms 104440 KB Output is correct