Submission #48449

# Submission time Handle Problem Language Result Execution time Memory
48449 2018-05-13T16:14:51 Z Pajaraja Tracks in the Snow (BOI13_tracks) C++17
97.8125 / 100
2000 ms 685856 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<17000000;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 69 ms 6392 KB Output is correct
2 Correct 29 ms 6392 KB Output is correct
3 Correct 26 ms 6392 KB Output is correct
4 Correct 42 ms 6524 KB Output is correct
5 Correct 33 ms 6524 KB Output is correct
6 Correct 29 ms 6524 KB Output is correct
7 Correct 26 ms 6524 KB Output is correct
8 Correct 27 ms 6524 KB Output is correct
9 Correct 30 ms 6524 KB Output is correct
10 Correct 33 ms 6524 KB Output is correct
11 Correct 32 ms 6524 KB Output is correct
12 Correct 49 ms 6524 KB Output is correct
13 Correct 33 ms 6524 KB Output is correct
14 Correct 33 ms 6524 KB Output is correct
15 Correct 56 ms 6524 KB Output is correct
16 Correct 57 ms 6804 KB Output is correct
17 Correct 50 ms 6804 KB Output is correct
18 Correct 45 ms 6836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 32060 KB Output is correct
2 Correct 164 ms 32060 KB Output is correct
3 Correct 897 ms 105776 KB Output is correct
4 Correct 266 ms 105776 KB Output is correct
5 Correct 599 ms 105776 KB Output is correct
6 Correct 1608 ms 178776 KB Output is correct
7 Correct 75 ms 178776 KB Output is correct
8 Correct 57 ms 178776 KB Output is correct
9 Correct 31 ms 178776 KB Output is correct
10 Correct 28 ms 178776 KB Output is correct
11 Correct 58 ms 178776 KB Output is correct
12 Correct 28 ms 178776 KB Output is correct
13 Correct 155 ms 178776 KB Output is correct
14 Correct 98 ms 178776 KB Output is correct
15 Correct 99 ms 178776 KB Output is correct
16 Correct 82 ms 178776 KB Output is correct
17 Correct 406 ms 178776 KB Output is correct
18 Correct 340 ms 178776 KB Output is correct
19 Correct 308 ms 178776 KB Output is correct
20 Correct 284 ms 178776 KB Output is correct
21 Correct 595 ms 178776 KB Output is correct
22 Correct 673 ms 178776 KB Output is correct
23 Correct 645 ms 178776 KB Output is correct
24 Correct 554 ms 178776 KB Output is correct
25 Correct 1312 ms 178776 KB Output is correct
26 Execution timed out 2013 ms 685856 KB Time limit exceeded
27 Correct 1570 ms 685856 KB Output is correct
28 Correct 1624 ms 685856 KB Output is correct
29 Correct 1560 ms 685856 KB Output is correct
30 Correct 1582 ms 685856 KB Output is correct
31 Correct 1390 ms 685856 KB Output is correct
32 Correct 1727 ms 685856 KB Output is correct