답안 #101685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101685 2019-03-19T10:21:20 Z jamielim Tracks in the Snow (BOI13_tracks) C++14
100 / 100
999 ms 110692 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h,w;
	scanf("%d%d",&h,&w);
	char grid[h+5][w+5];
	for(int i=0;i<h;i++)scanf("%s",grid[i]);
	deque<pair<int,int> > q;
	q.push_back(make_pair(0,0));
	int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
	int dist[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)dist[i][j]=1000000010;
	}
	dist[0][0]=1;
	while(!q.empty()){
		pair<int,int> cur=q.front();q.pop_front();
		for(int i=0;i<4;i++){
			int nx=cur.first+dx[i],ny=cur.second+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&grid[nx][ny]!='.'){
				if(grid[nx][ny]==grid[cur.first][cur.second]){
					if(dist[nx][ny]>dist[cur.first][cur.second]){
						dist[nx][ny]=dist[cur.first][cur.second];
						q.push_front(make_pair(nx,ny));
					}
				}else{
					if(dist[nx][ny]>dist[cur.first][cur.second]+1){
						dist[nx][ny]=dist[cur.first][cur.second]+1;
						q.push_back(make_pair(nx,ny));
					}
				}
			}
		}
	}
	int ans=1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(dist[i][j]<1000000010)ans=max(ans,dist[i][j]);
		}
	}
	printf("%d",ans);
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&h,&w);
  ~~~~~^~~~~~~~~~~~~~
tracks.cpp:7:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<h;i++)scanf("%s",grid[i]);
                      ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1536 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 8 ms 768 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 17 ms 1536 KB Output is correct
16 Correct 18 ms 1536 KB Output is correct
17 Correct 13 ms 1536 KB Output is correct
18 Correct 11 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 51 ms 8016 KB Output is correct
3 Correct 302 ms 78712 KB Output is correct
4 Correct 90 ms 18688 KB Output is correct
5 Correct 165 ms 44508 KB Output is correct
6 Correct 948 ms 91980 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 53 ms 7936 KB Output is correct
14 Correct 33 ms 4736 KB Output is correct
15 Correct 23 ms 5248 KB Output is correct
16 Correct 28 ms 3428 KB Output is correct
17 Correct 157 ms 20344 KB Output is correct
18 Correct 97 ms 19836 KB Output is correct
19 Correct 86 ms 18680 KB Output is correct
20 Correct 71 ms 17144 KB Output is correct
21 Correct 173 ms 45944 KB Output is correct
22 Correct 169 ms 44412 KB Output is correct
23 Correct 275 ms 38392 KB Output is correct
24 Correct 151 ms 44792 KB Output is correct
25 Correct 495 ms 78680 KB Output is correct
26 Correct 912 ms 110692 KB Output is correct
27 Correct 783 ms 97056 KB Output is correct
28 Correct 937 ms 92092 KB Output is correct
29 Correct 999 ms 89844 KB Output is correct
30 Correct 899 ms 94592 KB Output is correct
31 Correct 762 ms 51068 KB Output is correct
32 Correct 878 ms 95440 KB Output is correct