답안 #442015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442015 2021-07-06T18:14:07 Z iag99 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1536 ms 118856 KB
#include<bits/stdc++.h>
#define ll long long
#define mod  998244353
using namespace std;
int h,w;
vector<int> dx={1, -1, 0, 0};
vector<int> dy={0, 0, 1, -1};

int depth[4000][4000], ans = 1;
char grid[4000][4000];
bool isfree(int x, int y)
{
	if(x>=0 && x<h && y>=0 && y<w && grid[x][y]!='.')
	{
		return true;
	}
	return false;
}
int main() 
{
	

	cin>>h>>w;
	for(int i=0; i<h; i++)
	{
		for(int j=0; j<w; j++)
		{
			cin>>grid[i][j];
		}
	}
	deque<pair<int,int>> q;
	q.push_back({0,0});
	depth[0][0]=1;
	while(!q.empty())
	{
		pair<int,int> cur=q.front();
		q.pop_front();
		ans=max(ans, depth[cur.first][cur.second]);
		for(int i=0; i<4; i++)
		{
			int x=cur.first+dx[i];
			int y=cur.second+dy[i];
			if(isfree(x,y) && depth[x][y]==0)
			{
				if(grid[x][y]==grid[cur.first][cur.second])
				{
					depth[x][y]=depth[cur.first][cur.second];
					q.push_front({x,y});
				}
				else
				{
					depth[x][y]=depth[cur.first][cur.second]+1;
					q.push_back({x,y});
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 5068 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 17 ms 4940 KB Output is correct
5 Correct 8 ms 2764 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 7 ms 2380 KB Output is correct
11 Correct 5 ms 1996 KB Output is correct
12 Correct 10 ms 2892 KB Output is correct
13 Correct 8 ms 2844 KB Output is correct
14 Correct 8 ms 2764 KB Output is correct
15 Correct 28 ms 4980 KB Output is correct
16 Correct 28 ms 5096 KB Output is correct
17 Correct 24 ms 4884 KB Output is correct
18 Correct 17 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 30584 KB Output is correct
2 Correct 136 ms 13376 KB Output is correct
3 Correct 1113 ms 57720 KB Output is correct
4 Correct 294 ms 29036 KB Output is correct
5 Correct 698 ms 44252 KB Output is correct
6 Correct 1532 ms 92276 KB Output is correct
7 Correct 21 ms 32004 KB Output is correct
8 Correct 20 ms 30592 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
11 Correct 20 ms 31468 KB Output is correct
12 Correct 3 ms 1484 KB Output is correct
13 Correct 134 ms 13400 KB Output is correct
14 Correct 82 ms 9556 KB Output is correct
15 Correct 80 ms 12080 KB Output is correct
16 Correct 56 ms 5044 KB Output is correct
17 Correct 342 ms 24772 KB Output is correct
18 Correct 314 ms 31600 KB Output is correct
19 Correct 284 ms 28980 KB Output is correct
20 Correct 251 ms 22040 KB Output is correct
21 Correct 664 ms 43380 KB Output is correct
22 Correct 678 ms 44432 KB Output is correct
23 Correct 662 ms 35960 KB Output is correct
24 Correct 647 ms 40872 KB Output is correct
25 Correct 1346 ms 78444 KB Output is correct
26 Correct 1068 ms 118856 KB Output is correct
27 Correct 1403 ms 105048 KB Output is correct
28 Correct 1516 ms 92044 KB Output is correct
29 Correct 1536 ms 90532 KB Output is correct
30 Correct 1442 ms 94856 KB Output is correct
31 Correct 1070 ms 63452 KB Output is correct
32 Correct 1363 ms 90356 KB Output is correct