Submission #48452

# Submission time Handle Problem Language Result Execution time Memory
48452 2018-05-13T16:16:15 Z Pajaraja Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1879 ms 685748 KB
#include <bits/stdc++.h>
using namespace std;
int t[4007][4007],vi[4007][4007],n,m;
queue<pair<int,int> > q[3];
void dfs(int x,int y,int k)
{
	if(x<0 || y<0 || x>=n || y>=m || vi[x][y]) return;
	if(t[x][y]!=k)
	{
		if(t[x][y]==3-k) q[3-k].push(make_pair(x,y));
		return;
	}
	vi[x][y]=true;
	dfs(x-1,y,k);
	dfs(x+1,y,k);
	dfs(x,y-1,k);
	dfs(x,y+1,k);
}
int main()
{
	int sol=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		for(int j=0;j<m;j++) t[i][j]=(s[j]=='F'?2:(s[j]=='R'?1:0));
	}
	q[t[0][0]].push(make_pair(0,0));
	for(int i=0;i<16000000;i++)
	{
		if(!q[1].empty())
		{
			sol++;
			while(!q[1].empty())
			{
				if(!vi[q[1].front().first][q[1].front().second]) dfs(q[1].front().first,q[1].front().second,1);
				q[1].pop();
			}
		}
		if(!q[2].empty())
		{
			sol++;
			while(!q[2].empty())
			{
				if(!vi[q[2].front().first][q[2].front().second]) dfs(q[2].front().first,q[2].front().second,2);
				q[2].pop();
			}
		}
	}
	printf("%d",sol);
}
# Verdict Execution time Memory Grader output
1 Correct 56 ms 6264 KB Output is correct
2 Correct 29 ms 6264 KB Output is correct
3 Correct 25 ms 6264 KB Output is correct
4 Correct 42 ms 6524 KB Output is correct
5 Correct 32 ms 6524 KB Output is correct
6 Correct 27 ms 6524 KB Output is correct
7 Correct 25 ms 6524 KB Output is correct
8 Correct 26 ms 6524 KB Output is correct
9 Correct 26 ms 6524 KB Output is correct
10 Correct 29 ms 6524 KB Output is correct
11 Correct 29 ms 6524 KB Output is correct
12 Correct 35 ms 6524 KB Output is correct
13 Correct 31 ms 6524 KB Output is correct
14 Correct 31 ms 6524 KB Output is correct
15 Correct 51 ms 6524 KB Output is correct
16 Correct 53 ms 6524 KB Output is correct
17 Correct 46 ms 6524 KB Output is correct
18 Correct 40 ms 6600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 31816 KB Output is correct
2 Correct 144 ms 31816 KB Output is correct
3 Correct 843 ms 105620 KB Output is correct
4 Correct 252 ms 105620 KB Output is correct
5 Correct 556 ms 105620 KB Output is correct
6 Correct 1618 ms 178780 KB Output is correct
7 Correct 55 ms 178780 KB Output is correct
8 Correct 55 ms 178780 KB Output is correct
9 Correct 29 ms 178780 KB Output is correct
10 Correct 26 ms 178780 KB Output is correct
11 Correct 54 ms 178780 KB Output is correct
12 Correct 27 ms 178780 KB Output is correct
13 Correct 163 ms 178780 KB Output is correct
14 Correct 93 ms 178780 KB Output is correct
15 Correct 92 ms 178780 KB Output is correct
16 Correct 82 ms 178780 KB Output is correct
17 Correct 361 ms 178780 KB Output is correct
18 Correct 310 ms 178780 KB Output is correct
19 Correct 257 ms 178780 KB Output is correct
20 Correct 243 ms 178780 KB Output is correct
21 Correct 558 ms 178780 KB Output is correct
22 Correct 605 ms 178780 KB Output is correct
23 Correct 646 ms 178780 KB Output is correct
24 Correct 540 ms 178780 KB Output is correct
25 Correct 1136 ms 178780 KB Output is correct
26 Correct 1879 ms 685748 KB Output is correct
27 Correct 1540 ms 685748 KB Output is correct
28 Correct 1596 ms 685748 KB Output is correct
29 Correct 1542 ms 685748 KB Output is correct
30 Correct 1594 ms 685748 KB Output is correct
31 Correct 1338 ms 685748 KB Output is correct
32 Correct 1720 ms 685748 KB Output is correct