Submission #1189381

#TimeUsernameProblemLanguageResultExecution timeMemory
1189381pete555Tracks in the Snow (BOI13_tracks)C++17
100 / 100
400 ms111936 KiB
#include<bits/stdc++.h>
using namespace std;

#define pi pair<int,int>
#define ll long long
#define pb push_back
#define pf push_front

void fileIO(string filename) {
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

const int MOD = 1e9+7;
const int dx[] {0, 1, 0, -1};
const int dy[] {1, 0, -1, 0};

int main()
{
	cin.tie(0)->sync_with_stdio(false);
	//fileIO("");
	int n, m;
	cin >> n >> m;
	string g[n];
	for(int i = 0; i < n; i++) cin >> g[i];
	int d[n][m] {};
	d[0][0] = 1;
	deque<pi> q;
	q.pb({0, 0});
	int ans = 1;
	while(q.size()){
		pi u = q.front();
		ans = max(ans, d[u.first][u.second]);
		q.pop_front();
		for(int i = 0; i < 4; i++){
			int x = u.first + dx[i];
			int y = u.second + dy[i];
			if(0 <= x and x < n and 0 <= y and y < m){
				if(d[x][y] == 0 and g[x][y] != '.'){
					if(g[u.first][u.second] == g[x][y]){
						d[x][y] = d[u.first][u.second];
						q.push_front({x, y});
					}
					else{
						d[x][y] = d[u.first][u.second] + 1;
						q.push_back({x, y});
					}
				}
			}
		}
	}
	cout << ans << '\n';
}

Compilation message (stderr)

tracks.cpp: In function 'void fileIO(std::string)':
tracks.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen((filename + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen((filename + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...