Submission #575987

# Submission time Handle Problem Language Result Execution time Memory
575987 2022-06-12T02:35:11 Z OnionEgg Tracks in the Snow (BOI13_tracks) C++17
100 / 100
594 ms 231780 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#define ll long long
#define fas ios::sync_with_stdio(0); cout.tie(0); cin.tie(0)
#define el "\n"
#define fi first	
#define se second
#define th third
#define taskName "codefuck"
using namespace std;
const ll mod = 1e9+7;
ll dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
ll n, m, depth[4005][4005], res;
string snow[4000];
bool inside(ll x, ll y)
{
	return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}
void solve()
{
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> snow[i];
	deque<pair<ll, ll>>q;
	q.push_back({0, 0});
	depth[0][0] = 1;
	res = 1;
	while(q.size())
	{
		pair<ll, ll> c = q.front();
		q.pop_front();
		res = max(res, depth[c.fi][c.se]);
		for(int i = 0; i < 4; i++)
		{
			ll x = c.fi + dx[i], y = c.se + dy[i];
			if(inside(x, y) && depth[x][y] == 0)
			{
				if(snow[x][y] == snow[c.fi][c.se])
				{
					depth[x][y] = depth[c.fi][c.se];
					q.push_front({x, y});
				}
				else
				{
					depth[x][y] = depth[c.fi][c.se] + 1;
					q.push_back({x, y});
				}
			}
		}
	}
	cout << res;
}																	
int main()
{
	fas;
    if (fopen(taskName".inp", "r"))
    {
        freopen(taskName".inp", "r", stdin);
        freopen(taskName".out", "w", stdout);
    }
    ll testcase = 1;
	//cin >> testcase;
	while(testcase--)
	{
		solve();
	}
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(taskName".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(taskName".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4820 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 7 ms 4308 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 848 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
11 Correct 3 ms 1748 KB Output is correct
12 Correct 5 ms 2468 KB Output is correct
13 Correct 3 ms 2260 KB Output is correct
14 Correct 3 ms 2244 KB Output is correct
15 Correct 12 ms 4564 KB Output is correct
16 Correct 17 ms 4820 KB Output is correct
17 Correct 12 ms 4620 KB Output is correct
18 Correct 7 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16212 KB Output is correct
2 Correct 33 ms 14960 KB Output is correct
3 Correct 175 ms 84128 KB Output is correct
4 Correct 72 ms 42676 KB Output is correct
5 Correct 126 ms 66772 KB Output is correct
6 Correct 594 ms 177752 KB Output is correct
7 Correct 14 ms 16852 KB Output is correct
8 Correct 11 ms 16200 KB Output is correct
9 Correct 2 ms 976 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 10 ms 16468 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 39 ms 15004 KB Output is correct
14 Correct 22 ms 9896 KB Output is correct
15 Correct 19 ms 14276 KB Output is correct
16 Correct 17 ms 6476 KB Output is correct
17 Correct 87 ms 31968 KB Output is correct
18 Correct 71 ms 46956 KB Output is correct
19 Correct 78 ms 42556 KB Output is correct
20 Correct 45 ms 26908 KB Output is correct
21 Correct 106 ms 57852 KB Output is correct
22 Correct 144 ms 66468 KB Output is correct
23 Correct 165 ms 53936 KB Output is correct
24 Correct 108 ms 56596 KB Output is correct
25 Correct 387 ms 151380 KB Output is correct
26 Correct 385 ms 231780 KB Output is correct
27 Correct 504 ms 204480 KB Output is correct
28 Correct 578 ms 178344 KB Output is correct
29 Correct 587 ms 175276 KB Output is correct
30 Correct 523 ms 184384 KB Output is correct
31 Correct 537 ms 111284 KB Output is correct
32 Correct 406 ms 175708 KB Output is correct