Submission #969846

# Submission time Handle Problem Language Result Execution time Memory
969846 2024-04-25T16:53:06 Z starchan Tracks in the Snow (BOI13_tracks) C++17
100 / 100
564 ms 116164 KB
#include<bits/stdc++.h>
using namespace std;
#define in array<int, 2>
#define pf push_front
#define pb push_back
#define pob pop_back
#define pof pop_front
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)

const int LMX = 2e7;
const int INF = LMX+1e5;

char g[LMX]; int n, m;
vector<int> d(LMX, INF);

signed main()
{
	fast();
	cin >> n >> m;
	vector<int> dt = {+m, -m, +1, -1}; 
	for(int i = 0; i < m*n; i++)
		cin >> g[i];
	deque<int> pq;
	pq.pf(0); d[0] = 0;
	while(pq.size())
	{
		int u = pq.front(); pq.pof();
		for(auto x: dt)
		{
			int v = u+x;
			if((v < 0) || (v >= (n*m)) || (g[v] == '.'))
				continue;
			if((x == +1) && (v%m == 0))
				continue;
			if((x == -1) && (u%m == 0))
				continue;
			int cn = (g[u] != g[v]); 
			if(d[v] > (d[u]+cn))
			{
				d[v] = d[u]+cn;
				if(cn)
					pq.pb(v);
				else
					pq.pf(v);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < n*m; i++)
	{
		if(g[i] != '.')
			ans = max(ans, d[i]);
	}
	for(int i = 0; i < n*m; i++)
	{
		if(g[i] != '.')
			ans = max(ans, ++d[i]);
	}
	cout << ans << "\n";
	return 0;
}	
# Verdict Execution time Memory Grader output
1 Correct 27 ms 80984 KB Output is correct
2 Correct 17 ms 78684 KB Output is correct
3 Correct 15 ms 78684 KB Output is correct
4 Correct 20 ms 78940 KB Output is correct
5 Correct 17 ms 78684 KB Output is correct
6 Correct 15 ms 78684 KB Output is correct
7 Correct 16 ms 78552 KB Output is correct
8 Correct 15 ms 78684 KB Output is correct
9 Correct 16 ms 78684 KB Output is correct
10 Correct 17 ms 78656 KB Output is correct
11 Correct 17 ms 78684 KB Output is correct
12 Correct 20 ms 78684 KB Output is correct
13 Correct 17 ms 78684 KB Output is correct
14 Correct 17 ms 78680 KB Output is correct
15 Correct 23 ms 80992 KB Output is correct
16 Correct 24 ms 80984 KB Output is correct
17 Correct 29 ms 80988 KB Output is correct
18 Correct 20 ms 78940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 78728 KB Output is correct
2 Correct 49 ms 80960 KB Output is correct
3 Correct 258 ms 95324 KB Output is correct
4 Correct 85 ms 83020 KB Output is correct
5 Correct 160 ms 89164 KB Output is correct
6 Correct 525 ms 102056 KB Output is correct
7 Correct 16 ms 78668 KB Output is correct
8 Correct 16 ms 78684 KB Output is correct
9 Correct 17 ms 78684 KB Output is correct
10 Correct 16 ms 78572 KB Output is correct
11 Correct 17 ms 78668 KB Output is correct
12 Correct 16 ms 78684 KB Output is correct
13 Correct 49 ms 80988 KB Output is correct
14 Correct 34 ms 80984 KB Output is correct
15 Correct 37 ms 80728 KB Output is correct
16 Correct 31 ms 80728 KB Output is correct
17 Correct 103 ms 82768 KB Output is correct
18 Correct 80 ms 82768 KB Output is correct
19 Correct 86 ms 82772 KB Output is correct
20 Correct 70 ms 82772 KB Output is correct
21 Correct 173 ms 89432 KB Output is correct
22 Correct 164 ms 88912 KB Output is correct
23 Correct 197 ms 87124 KB Output is correct
24 Correct 155 ms 88916 KB Output is correct
25 Correct 361 ms 95312 KB Output is correct
26 Correct 321 ms 116164 KB Output is correct
27 Correct 433 ms 108636 KB Output is correct
28 Correct 550 ms 102208 KB Output is correct
29 Correct 564 ms 101320 KB Output is correct
30 Correct 488 ms 104264 KB Output is correct
31 Correct 403 ms 89160 KB Output is correct
32 Correct 400 ms 102780 KB Output is correct