답안 #886643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886643 2023-12-12T14:37:51 Z MongHwa Tracks in the Snow (BOI13_tracks) C++17
100 / 100
554 ms 131632 KB
#include <iostream>
#include <queue>
#include <tuple>
using namespace std;

#define INF 0x7f7f7f7f

string stage[4001];
int status[4001][4001];

int dirx[] = {1, -1, 0, 0};
int diry[] = {0, 0, 1, -1};
deque<pair<int, int>> dq;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int h, w;
	cin >> h >> w;

	int sum = 0;
	for(int i = 0; i < h; i++)
	{
		cin >> stage[i];
		for(int j = 0; j < w; j++)
			status[i][j] = INF;
	}

	int ans = 0;
	status[0][0] = 1;
	dq.push_front({0, 0});
	while(!dq.empty())
	{
		int x, y;
		tie(x, y) = dq.front(); dq.pop_front();
		
		for(int i = 0; i < 4; i++)
		{
			int dx = x + dirx[i];
			int dy = y + diry[i];

			if(dx < 0 || dx >= h || dy < 0 || dy >= w)
				continue;
			if(stage[dx][dy] == '.')
				continue;

			if(stage[dx][dy] == stage[x][y] && status[dx][dy] > status[x][y])
			{
				status[dx][dy] = status[x][y];
				ans = max(ans, status[dx][dy]);
				dq.push_front({dx, dy});
			}
			else if(stage[dx][dy] != stage[x][y] && status[dx][dy] > status[x][y]+1)
			{
				status[dx][dy] = status[x][y]+1;
				ans = max(ans, status[dx][dy]);
				dq.push_back({dx, dy});
			}
		}
	}
	
	cout << ans << '\n';
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:23:6: warning: unused variable 'sum' [-Wunused-variable]
   23 |  int sum = 0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9308 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 7 ms 9376 KB Output is correct
5 Correct 3 ms 6744 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 5 ms 7000 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 9 ms 9300 KB Output is correct
16 Correct 11 ms 9208 KB Output is correct
17 Correct 7 ms 9308 KB Output is correct
18 Correct 6 ms 9380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 62024 KB Output is correct
2 Correct 31 ms 24156 KB Output is correct
3 Correct 154 ms 96504 KB Output is correct
4 Correct 41 ms 39088 KB Output is correct
5 Correct 74 ms 66384 KB Output is correct
6 Correct 509 ms 109936 KB Output is correct
7 Correct 8 ms 62296 KB Output is correct
8 Correct 8 ms 62044 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 7 ms 62044 KB Output is correct
12 Correct 1 ms 4692 KB Output is correct
13 Correct 31 ms 24256 KB Output is correct
14 Correct 18 ms 16732 KB Output is correct
15 Correct 10 ms 19036 KB Output is correct
16 Correct 16 ms 8028 KB Output is correct
17 Correct 73 ms 41820 KB Output is correct
18 Correct 43 ms 41660 KB Output is correct
19 Correct 41 ms 39000 KB Output is correct
20 Correct 38 ms 36432 KB Output is correct
21 Correct 91 ms 68948 KB Output is correct
22 Correct 77 ms 66640 KB Output is correct
23 Correct 149 ms 55716 KB Output is correct
24 Correct 85 ms 68436 KB Output is correct
25 Correct 286 ms 96644 KB Output is correct
26 Correct 291 ms 131632 KB Output is correct
27 Correct 385 ms 123164 KB Output is correct
28 Correct 554 ms 110056 KB Output is correct
29 Correct 502 ms 108480 KB Output is correct
30 Correct 462 ms 112692 KB Output is correct
31 Correct 462 ms 73552 KB Output is correct
32 Correct 326 ms 111676 KB Output is correct