| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 625187 | Stavab | Tracks in the Snow (BOI13_tracks) | C++14 | 1173 ms | 636720 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 <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
vector<vector<char>> field;
vector<vector<int>> turn;
int h, w, answer = 1;
queue<pair<int, int>> points;
void scan(pair<int, int> p)
{
int i = p.first;
int j = p.second;
if(i != 0)
{
if(!turn[i - 1][j] && field[i - 1][j] != '.')
{
if(field[i - 1][j] == field[i][j])
{
turn[i - 1][j] = turn[i][j];
scan({i - 1, j});
}
else
{
turn[i - 1][j] = turn[i][j] + 1;
points.push({i - 1, j});
}
}
}
if(j != 0)
{
if(!turn[i][j - 1] && field[i][j - 1] != '.')
{
if(field[i][j - 1] == field[i][j])
{
turn[i][j - 1] = turn[i][j];
scan({i, j - 1});
}
else
{
turn[i][j - 1] = turn[i][j] + 1;
points.push({i, j - 1});
}
}
}
if(i != h - 1)
{
if(!turn[i + 1][j] && field[i + 1][j] != '.')
{
if(field[i + 1][j] == field[i][j])
{
turn[i + 1][j] = turn[i][j];
scan({i + 1, j});
}
else
{
turn[i + 1][j] = turn[i][j] + 1;
points.push({i + 1, j});
}
}
}
if(j != w - 1)
{
if(!turn[i][j + 1] && field[i][j + 1] != '.')
{
if(field[i][j + 1] == field[i][j])
{
turn[i][j + 1] = turn[i][j];
scan({i, j + 1});
}
else
{
turn[i][j + 1] = turn[i][j] + 1;
points.push({i, j + 1});
}
}
}
}
int main()
{
scanf("%d %d", &h, &w);
field.assign(h, vector<char>(w));
turn.assign(h, vector<int>(w, 0));
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++)
scanf(" %c", &field[i][j]);
turn[0][0] = 1;
points.push({0, 0});
while(!points.empty())
{
answer = max(answer, turn[points.front().first][points.front().second]);
scan(points.front());
points.pop();
}
printf("%d\n", answer);
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
