Submission #493783

# Submission time Handle Problem Language Result Execution time Memory
493783 2021-12-13T00:55:05 Z goodluck2020 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
827 ms 175916 KB
#include <bits/stdc++.h>
#define task "tracks"

using namespace std;
const int N = 4e3 + 5;
int n, m, dist[N][N], Visited[N][N], ans(0);
char A[N][N];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
bool inside(int x, int y)
{
    if(x < 1 || x > n || y < 1 || y > m) return 0;
    return 1;
}
struct Data
{
    int x, y;
};
deque < Data > dq;
void BFS01()
{
    dq.push_back({1, 1}); Visited[1][1] = 1; dist[1][1] = 1;
    while(!dq.empty())
    {
        int x = dq.front().x;
        int y = dq.front().y;
        dq.pop_front();
        for(int i = 0; i < 4; i++)
        {
            int u = x + dx[i];
            int v = y + dy[i];
            if(inside(u, v) && !Visited[u][v] && A[u][v] != '.')
            {
                if(A[u][v] == A[x][y])
                {
                    dq.push_front({u, v});
                    dist[u][v] = dist[x][y];
                    Visited[u][v] = 1;
                }
                else
                {
                    dq.push_back({u, v});
                    dist[u][v] = dist[x][y] + 1;
                    Visited[u][v] = 1;
                }
            }
        }
    }
}
int main()
{
    if(fopen(task ".inp","r"))
    {
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) cin >> A[i][j];
    BFS01();
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        ans = max(ans, dist[i][j]);
    cout << ans;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 8268 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 9 ms 7756 KB Output is correct
5 Correct 5 ms 4300 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1092 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 3 ms 3148 KB Output is correct
12 Correct 6 ms 4556 KB Output is correct
13 Correct 4 ms 4408 KB Output is correct
14 Correct 4 ms 4300 KB Output is correct
15 Correct 13 ms 8052 KB Output is correct
16 Correct 13 ms 8296 KB Output is correct
17 Correct 12 ms 8012 KB Output is correct
18 Correct 9 ms 7756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 46372 KB Output is correct
2 Correct 58 ms 23364 KB Output is correct
3 Correct 357 ms 101284 KB Output is correct
4 Correct 110 ms 52292 KB Output is correct
5 Correct 253 ms 78996 KB Output is correct
6 Correct 686 ms 156360 KB Output is correct
7 Correct 23 ms 48400 KB Output is correct
8 Correct 25 ms 46360 KB Output is correct
9 Correct 2 ms 844 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 23 ms 47436 KB Output is correct
12 Correct 2 ms 2252 KB Output is correct
13 Correct 56 ms 23304 KB Output is correct
14 Correct 33 ms 16068 KB Output is correct
15 Correct 32 ms 20916 KB Output is correct
16 Correct 25 ms 8844 KB Output is correct
17 Correct 154 ms 43352 KB Output is correct
18 Correct 121 ms 57420 KB Output is correct
19 Correct 107 ms 52292 KB Output is correct
20 Correct 86 ms 39136 KB Output is correct
21 Correct 229 ms 76264 KB Output is correct
22 Correct 253 ms 78896 KB Output is correct
23 Correct 290 ms 64180 KB Output is correct
24 Correct 246 ms 71184 KB Output is correct
25 Correct 564 ms 143072 KB Output is correct
26 Correct 691 ms 175916 KB Output is correct
27 Correct 782 ms 161504 KB Output is correct
28 Correct 813 ms 156544 KB Output is correct
29 Correct 827 ms 154280 KB Output is correct
30 Correct 790 ms 157796 KB Output is correct
31 Correct 633 ms 115580 KB Output is correct
32 Correct 766 ms 159116 KB Output is correct