Submission #875928

# Submission time Handle Problem Language Result Execution time Memory
875928 2023-11-20T18:58:52 Z Akshat369 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
657 ms 57804 KB
#include <bits/stdc++.h>

using namespace std;

const int N=4e3+5;
int h, w, cnt, dx[4]={1, 0, 0, -1}, dy[4]={0, 1, -1, 0};
char mp[N][N], c;
queue<pair<int, int>> q, nq;
bool vs[N][N];

int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
//#ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
    cin>>h>>w;
    for (int i=1; i<=h; i++) for (int j=1; j<=w; j++) cin>>mp[i][j];
    nq.push({1, 1});
    vs[1][1]=1;
    while (!nq.empty())
    {
        cnt++;
        c=mp[nq.front().first][nq.front().second];
        while (!nq.empty()) q.push(nq.front()), nq.pop();
        while (!q.empty())
        {
            auto [x, y]=q.front();
            q.pop();
            for (int i=0; i<4; i++)
            {
                int nx=x+dx[i], ny=y+dy[i];
                if (nx<1||nx>h||ny<1||ny>w||mp[nx][ny]=='.'||vs[nx][ny]) continue;
                vs[nx][ny]=1;
                if (mp[nx][ny]==c) q.push({nx, ny});
                else nq.push({nx, ny});
            }
        }
    }
    cout<<cnt;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6744 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 8 ms 6628 KB Output is correct
5 Correct 3 ms 5604 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 3 ms 5468 KB Output is correct
11 Correct 2 ms 3164 KB Output is correct
12 Correct 5 ms 5724 KB Output is correct
13 Correct 3 ms 5720 KB Output is correct
14 Correct 3 ms 5724 KB Output is correct
15 Correct 11 ms 6748 KB Output is correct
16 Correct 11 ms 6600 KB Output is correct
17 Correct 8 ms 6492 KB Output is correct
18 Correct 6 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 31320 KB Output is correct
2 Correct 41 ms 13000 KB Output is correct
3 Correct 257 ms 47280 KB Output is correct
4 Correct 61 ms 21584 KB Output is correct
5 Correct 165 ms 35156 KB Output is correct
6 Correct 612 ms 57804 KB Output is correct
7 Correct 8 ms 31836 KB Output is correct
8 Correct 11 ms 31424 KB Output is correct
9 Correct 2 ms 2532 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 8 ms 31580 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 41 ms 12876 KB Output is correct
14 Correct 30 ms 10840 KB Output is correct
15 Correct 19 ms 11352 KB Output is correct
16 Correct 22 ms 6792 KB Output is correct
17 Correct 104 ms 22592 KB Output is correct
18 Correct 69 ms 22352 KB Output is correct
19 Correct 64 ms 21584 KB Output is correct
20 Correct 61 ms 18768 KB Output is correct
21 Correct 162 ms 35924 KB Output is correct
22 Correct 182 ms 35160 KB Output is correct
23 Correct 201 ms 30164 KB Output is correct
24 Correct 144 ms 35664 KB Output is correct
25 Correct 333 ms 47316 KB Output is correct
26 Correct 324 ms 42576 KB Output is correct
27 Correct 471 ms 49092 KB Output is correct
28 Correct 657 ms 57672 KB Output is correct
29 Correct 598 ms 56004 KB Output is correct
30 Correct 541 ms 54724 KB Output is correct
31 Correct 459 ms 37968 KB Output is correct
32 Correct 428 ms 48208 KB Output is correct