# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1189381 | pete555 | Tracks in the Snow (BOI13_tracks) | C++17 | 400 ms | 111936 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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |