답안 #763178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763178 2023-06-22T05:56:27 Z Kongggwp Tracks in the Snow (BOI13_tracks) C++14
100 / 100
735 ms 191732 KB
#include<bits/stdc++.h>
using namespace std;
int n , m , dx[4] = {1,0,-1,0} , dy[4] = {0,1,0,-1} , dist[4005][4005] , vis[4005][4005] , ans=1;
char grid[4005][4005];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> m;
	for(int i=0 ; i<n ; i++)for(int j=0 ; j<m ; j++)cin >> grid[i][j];
	deque<pair<int,int>>q;
	q.push_front({0,0});
	vis[0][0] = 1;
	dist[0][0] = 1;
	while(q.size())
	{
		int x = q.front().first , y = q.front().second;
		q.pop_front();
		ans = max(ans , dist[x][y]);
		for(int k=0 ; k<4 ; k++)
		{
			int xx = x + dx[k] , yy = y + dy[k];
			if(xx<0 || yy<0 || xx>=n || yy>=m || grid[xx][yy] == '.' || vis[xx][yy])continue;
			if(grid[x][y] == grid[xx][yy])
			{
				q.push_front({xx , yy});
				dist[xx][yy] = dist[x][y];
			}
			else
			{
				q.push_back({xx , yy});
				dist[xx][yy] = dist[x][y] + 1;
			}
			vis[xx][yy] = 1;
		}
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8276 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 836 KB Output is correct
4 Correct 10 ms 7700 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 3 ms 3668 KB Output is correct
11 Correct 3 ms 3084 KB Output is correct
12 Correct 5 ms 4564 KB Output is correct
13 Correct 5 ms 4308 KB Output is correct
14 Correct 3 ms 4304 KB Output is correct
15 Correct 11 ms 7924 KB Output is correct
16 Correct 13 ms 8320 KB Output is correct
17 Correct 10 ms 8020 KB Output is correct
18 Correct 9 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 46292 KB Output is correct
2 Correct 47 ms 23364 KB Output is correct
3 Correct 298 ms 115240 KB Output is correct
4 Correct 107 ms 53980 KB Output is correct
5 Correct 176 ms 85824 KB Output is correct
6 Correct 735 ms 171076 KB Output is correct
7 Correct 24 ms 48464 KB Output is correct
8 Correct 22 ms 46288 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 19 ms 47412 KB Output is correct
12 Correct 2 ms 2256 KB Output is correct
13 Correct 47 ms 23408 KB Output is correct
14 Correct 30 ms 15968 KB Output is correct
15 Correct 27 ms 20944 KB Output is correct
16 Correct 21 ms 8932 KB Output is correct
17 Correct 121 ms 45416 KB Output is correct
18 Correct 101 ms 59268 KB Output is correct
19 Correct 90 ms 53980 KB Output is correct
20 Correct 75 ms 40764 KB Output is correct
21 Correct 174 ms 83576 KB Output is correct
22 Correct 166 ms 85824 KB Output is correct
23 Correct 224 ms 69840 KB Output is correct
24 Correct 176 ms 78204 KB Output is correct
25 Correct 544 ms 157004 KB Output is correct
26 Correct 487 ms 185972 KB Output is correct
27 Correct 620 ms 191732 KB Output is correct
28 Correct 704 ms 171076 KB Output is correct
29 Correct 713 ms 168572 KB Output is correct
30 Correct 647 ms 172968 KB Output is correct
31 Correct 533 ms 123632 KB Output is correct
32 Correct 568 ms 178964 KB Output is correct