# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441337 | WindChaser | Tracks in the Snow (BOI13_tracks) | C++11 | 117 ms | 68296 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if(name.size()){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
//CSES messageRoute
int h, w;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
char snow[4000][4000];
int numAni[4000][4000];
bool valid(int x, int y)
{
return (x > -1 && x < h && y > -1 && y < w && snow[x][y] != '.');
}
int main()
{
setIO();
cin >> h >> w;
for(int i = 0; i < h; i++)
{
string s;
cin >> s;
for(int j = 0; j < w; j++)
{
snow[i][j] = s.at(j);
}
}
deque<pair<int, int>> q;
q.push_back({0,0});
numAni[0][0] = 1;
int ans = 1;
cout << ans;
while(!q.empty())
{
pair<int, int> c = q.front();
q.pop_front();
int curAni = numAni[c.first][c.second];
ans = max(ans, curAni);
for(int i = 0; i < 4; i++)
{
int nx = c.first + dx[i];
int ny = c.second + dy[i];
if(valid && numAni[nx][ny] == 0)
{
if(snow[nx][ny] == snow[c.first][c.second])
{
numAni[nx][ny] = curAni;
q.push_front({nx,ny});
}
else
{
numAni[nx][ny] = curAni + 1;
q.push_back({nx,ny});
}
}
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |