Submission #556875

# Submission time Handle Problem Language Result Execution time Memory
556875 2022-05-04T08:49:57 Z Hanksburger Tracks in the Snow (BOI13_tracks) C++17
100 / 100
803 ms 972708 KB
#include <bits/stdc++.h>
using namespace std;
#define si short int
#define pii pair<si, si>
#define fi first
#define se second
pii dir[4]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pii > vec[2];
string a[4000];
si n, m;
int ans;
bool ok(pii u)
{
	return (u.fi>=0 && u.fi<n && u.se>=0 && u.se<m && a[u.fi][u.se]!='.');
}
void dfs(pii u)
{
	char x=a[u.fi][u.se];
	a[u.fi][u.se]='.';
	for (pii i:dir)
	{
		pii v=u;
		v.fi+=i.fi;
		v.se+=i.se;
		if (ok(v))
		{
			if (a[v.fi][v.se]==x)
				dfs(v);
			else
				vec[(ans&1)^1].push_back(v);
		}
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for (si i=0; i<n; i++)
		cin >> a[i];
	vec[0].push_back({0, 0});
	while (vec[ans&1].size())
	{
		for (pii u:vec[ans&1])
			dfs(u);
		vec[ans&1].clear();
		ans++;
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 980 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 1712 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 7 ms 724 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 580 KB Output is correct
15 Correct 12 ms 852 KB Output is correct
16 Correct 17 ms 1024 KB Output is correct
17 Correct 7 ms 724 KB Output is correct
18 Correct 7 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 42 ms 2336 KB Output is correct
3 Correct 195 ms 18680 KB Output is correct
4 Correct 33 ms 4688 KB Output is correct
5 Correct 112 ms 10580 KB Output is correct
6 Correct 663 ms 70144 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 39 ms 2260 KB Output is correct
14 Correct 23 ms 1596 KB Output is correct
15 Correct 11 ms 1644 KB Output is correct
16 Correct 23 ms 1324 KB Output is correct
17 Correct 101 ms 5128 KB Output is correct
18 Correct 42 ms 4948 KB Output is correct
19 Correct 30 ms 4692 KB Output is correct
20 Correct 42 ms 4308 KB Output is correct
21 Correct 111 ms 10948 KB Output is correct
22 Correct 132 ms 10612 KB Output is correct
23 Correct 200 ms 9368 KB Output is correct
24 Correct 92 ms 10580 KB Output is correct
25 Correct 221 ms 18716 KB Output is correct
26 Correct 803 ms 972708 KB Output is correct
27 Correct 627 ms 240392 KB Output is correct
28 Correct 660 ms 70512 KB Output is correct
29 Correct 639 ms 63136 KB Output is correct
30 Correct 610 ms 146688 KB Output is correct
31 Correct 703 ms 13656 KB Output is correct
32 Correct 536 ms 267752 KB Output is correct