Submission #142571

# Submission time Handle Problem Language Result Execution time Memory
142571 2019-08-09T17:36:51 Z nikolapesic2802 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1004 ms 130952 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define f first
#define s second
using namespace std;

const int N=4001;
char mat[N][N];
int dist[N][N];
vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
int h,w;
bool inside(int x,int y)
{
	return x>=0&&x<h&&y>=0&&y<w&&(mat[x][y]=='F'||mat[x][y]=='R');
}
int main()
{
	 cin >> h >> w;
	 for(int i=0;i<h;i++)
	 	scanf("%s",mat[i]);
	 deque<pair<int,int> > q;
	 q.pb({0,0});
	 dist[0][0]=1;
	 int sol=1;
	 while(q.size())
	 {
 		auto tr=q.front();
 		q.pop_front();
 		sol=max(sol,dist[tr.f][tr.s]);
 		for(int k=0;k<4;k++)
 		{
 			int x=tr.f+dx[k],y=tr.s+dy[k];
 			if(inside(x,y)&&dist[x][y]==0)
 			{
 				if(mat[x][y]==mat[tr.f][tr.s])
 				{
 					dist[x][y]=dist[tr.f][tr.s];
 					q.push_front({x,y});
 				}
 				else
 				{
 					dist[x][y]=dist[tr.f][tr.s]+1;
 					q.push_back({x,y});
 				}
 			}
 		}
 	}
 	printf("%i\n",sol);
}
    

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:22:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s",mat[i]);
    ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5624 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 14 ms 5240 KB Output is correct
5 Correct 7 ms 2936 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 6 ms 2552 KB Output is correct
11 Correct 7 ms 2168 KB Output is correct
12 Correct 11 ms 3064 KB Output is correct
13 Correct 6 ms 2936 KB Output is correct
14 Correct 8 ms 2936 KB Output is correct
15 Correct 23 ms 5340 KB Output is correct
16 Correct 26 ms 5468 KB Output is correct
17 Correct 16 ms 5268 KB Output is correct
18 Correct 14 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 30840 KB Output is correct
2 Correct 69 ms 14996 KB Output is correct
3 Correct 326 ms 73300 KB Output is correct
4 Correct 99 ms 32888 KB Output is correct
5 Correct 272 ms 53336 KB Output is correct
6 Correct 1004 ms 107976 KB Output is correct
7 Correct 36 ms 32252 KB Output is correct
8 Correct 33 ms 30840 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 3 ms 380 KB Output is correct
11 Correct 32 ms 31608 KB Output is correct
12 Correct 4 ms 1656 KB Output is correct
13 Correct 65 ms 15096 KB Output is correct
14 Correct 41 ms 10488 KB Output is correct
15 Correct 37 ms 13176 KB Output is correct
16 Correct 35 ms 5724 KB Output is correct
17 Correct 158 ms 28668 KB Output is correct
18 Correct 127 ms 35708 KB Output is correct
19 Correct 97 ms 32728 KB Output is correct
20 Correct 86 ms 25508 KB Output is correct
21 Correct 213 ms 52732 KB Output is correct
22 Correct 271 ms 53368 KB Output is correct
23 Correct 296 ms 43684 KB Output is correct
24 Correct 205 ms 49792 KB Output is correct
25 Correct 509 ms 94276 KB Output is correct
26 Correct 464 ms 130952 KB Output is correct
27 Correct 625 ms 121032 KB Output is correct
28 Correct 881 ms 108048 KB Output is correct
29 Correct 871 ms 106348 KB Output is correct
30 Correct 776 ms 110336 KB Output is correct
31 Correct 851 ms 73592 KB Output is correct
32 Correct 542 ms 106164 KB Output is correct