Submission #555305

# Submission time Handle Problem Language Result Execution time Memory
555305 2022-04-30T11:30:51 Z status_coding Tracks in the Snow (BOI13_tracks) C++14
100 / 100
824 ms 217420 KB
#include <bits/stdc++.h>

using namespace std;

struct pos
{
    int x, y, len;

    pos(int x, int y, int len)
    {
        this->x = x;
        this->y = y;
        this->len = len;
    }
};

int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

int n,m,ans;
char a[4005][4005];

int d[4005][4005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>m;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            cin>>a[i][j];

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            d[i][j] = -1;

    deque<pos> q;
    q.push_back(pos(1, 1, 1));

    while(!q.empty())
    {
        int x = q.front().x;
        int y = q.front().y;
        int len = q.front().len;
        q.pop_front();

        if(d[x][y] != -1)
            continue;

        d[x][y] = len;
        ans = len;

        for(int i=0; i<4; i++)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if(nx < 1 || nx > n || ny < 1 || ny > m || d[nx][ny] != -1 || a[nx][ny] == '.')
                continue;

            if(a[x][y] == a[nx][ny])
                q.push_front(pos(nx, ny, len));
            else
                q.push_back(pos(nx, ny, len+1));
        }
    }

    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 5460 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 10 ms 5412 KB Output is correct
5 Correct 4 ms 3036 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 712 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1104 KB Output is correct
10 Correct 3 ms 2516 KB Output is correct
11 Correct 3 ms 2260 KB Output is correct
12 Correct 7 ms 3156 KB Output is correct
13 Correct 4 ms 3032 KB Output is correct
14 Correct 3 ms 3024 KB Output is correct
15 Correct 15 ms 5512 KB Output is correct
16 Correct 18 ms 5516 KB Output is correct
17 Correct 12 ms 5272 KB Output is correct
18 Correct 9 ms 5416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 30804 KB Output is correct
2 Correct 58 ms 16536 KB Output is correct
3 Correct 339 ms 78916 KB Output is correct
4 Correct 86 ms 30028 KB Output is correct
5 Correct 216 ms 59428 KB Output is correct
6 Correct 808 ms 114424 KB Output is correct
7 Correct 13 ms 32212 KB Output is correct
8 Correct 13 ms 30928 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 12 ms 31724 KB Output is correct
12 Correct 2 ms 1620 KB Output is correct
13 Correct 58 ms 16596 KB Output is correct
14 Correct 33 ms 11228 KB Output is correct
15 Correct 26 ms 12292 KB Output is correct
16 Correct 27 ms 6228 KB Output is correct
17 Correct 146 ms 32420 KB Output is correct
18 Correct 96 ms 32032 KB Output is correct
19 Correct 91 ms 30084 KB Output is correct
20 Correct 80 ms 27888 KB Output is correct
21 Correct 199 ms 61280 KB Output is correct
22 Correct 214 ms 59464 KB Output is correct
23 Correct 277 ms 49676 KB Output is correct
24 Correct 186 ms 60748 KB Output is correct
25 Correct 463 ms 78792 KB Output is correct
26 Correct 819 ms 217420 KB Output is correct
27 Correct 663 ms 122740 KB Output is correct
28 Correct 824 ms 114320 KB Output is correct
29 Correct 793 ms 110460 KB Output is correct
30 Correct 774 ms 114668 KB Output is correct
31 Correct 702 ms 64612 KB Output is correct
32 Correct 687 ms 123540 KB Output is correct