답안 #199452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199452 2020-02-01T12:52:37 Z TadijaSebez Tracks in the Snow (BOI13_tracks) C++11
100 / 100
726 ms 112692 KB
#include <bits/stdc++.h>
using namespace std;
const int N=4050;
char s[N][N];
int dist[N][N],n,m;
int mv[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
bool ok(int x,int y){return x>=1 && x<=n && y>=1 && y<=m && s[x][y]!='.';}
int main(){
	scanf("%i %i",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dist[i][j]=1e9;
	deque<int> q;
	q.push_back(1*N+1);
	dist[1][1]=1;
	int ans=0;
	while(q.size()){
		int x=q.front()/N;
		int y=q.front()%N;
		q.pop_front();
		ans=max(ans,dist[x][y]);
		for(int k=0;k<4;k++){
			int i=x+mv[k][0];
			int j=y+mv[k][1];
			if(ok(i,j)){
				int w=s[x][y]!=s[i][j];
				if(dist[i][j]>dist[x][y]+w){
					dist[i][j]=dist[x][y]+w;
					if(w==0)q.push_front(i*N+j);
					else q.push_back(i*N+j);
				}
			}
		}
	}
	printf("%i\n",ans);
	return 0;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
tracks.cpp:10:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
                       ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 5496 KB Output is correct
2 Correct 5 ms 508 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 25 ms 5160 KB Output is correct
5 Correct 8 ms 3064 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 1144 KB Output is correct
10 Correct 9 ms 2680 KB Output is correct
11 Correct 7 ms 2168 KB Output is correct
12 Correct 9 ms 3064 KB Output is correct
13 Correct 9 ms 3096 KB Output is correct
14 Correct 8 ms 3064 KB Output is correct
15 Correct 17 ms 5496 KB Output is correct
16 Correct 17 ms 5496 KB Output is correct
17 Correct 15 ms 5400 KB Output is correct
18 Correct 14 ms 5164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 31096 KB Output is correct
2 Correct 51 ms 18008 KB Output is correct
3 Correct 293 ms 95228 KB Output is correct
4 Correct 86 ms 33656 KB Output is correct
5 Correct 180 ms 68276 KB Output is correct
6 Correct 666 ms 102252 KB Output is correct
7 Correct 24 ms 32504 KB Output is correct
8 Correct 25 ms 31096 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 22 ms 31968 KB Output is correct
12 Correct 6 ms 1656 KB Output is correct
13 Correct 49 ms 18180 KB Output is correct
14 Correct 30 ms 12024 KB Output is correct
15 Correct 30 ms 13176 KB Output is correct
16 Correct 27 ms 6648 KB Output is correct
17 Correct 120 ms 36344 KB Output is correct
18 Correct 129 ms 35832 KB Output is correct
19 Correct 81 ms 33760 KB Output is correct
20 Correct 66 ms 31224 KB Output is correct
21 Correct 155 ms 70624 KB Output is correct
22 Correct 179 ms 68340 KB Output is correct
23 Correct 224 ms 57528 KB Output is correct
24 Correct 166 ms 69616 KB Output is correct
25 Correct 438 ms 95224 KB Output is correct
26 Correct 406 ms 106764 KB Output is correct
27 Correct 580 ms 112692 KB Output is correct
28 Correct 726 ms 102332 KB Output is correct
29 Correct 709 ms 101096 KB Output is correct
30 Correct 677 ms 103216 KB Output is correct
31 Correct 590 ms 74200 KB Output is correct
32 Correct 552 ms 107404 KB Output is correct