Submission #734451

# Submission time Handle Problem Language Result Execution time Memory
734451 2023-05-02T12:15:28 Z rahidilbayramli Tracks in the Snow (BOI13_tracks) C++17
100 / 100
868 ms 130536 KB
#include<bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define sl set<ll>
#define all(v) v.begin(), v.end()
#define pb push_back
#define s second
#define f first
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
int n, m, i, j, depth[4001][4001];
int neighborx[4] = {-1, 1, 0, 0};
int neighbory[4] = {0, 0, 1, -1};
string a[4001];
bool isvalid(int c, int d)
{
    if(c < 0 || d < 0 || c >= n || d >= m || a[c][d] == '.')    return false;
    return true;
}
int main()
{
    cin >> n >> m;
    for(i = 0; i < n; i++)    cin >> a[i];
    depth[0][0] = 1;
    deque<pair<int, int>>q;
    q.push_back({0, 0});
    int ans = 0;
    while(!q.empty())
    {
        auto s = q.front();
        q.pop_front();
        int x = s.f, y = s.s;
        ans = max(ans, depth[x][y]);
        for(i = 0; i < 4; i++)
        {
            int nx = x + neighborx[i], ny = y + neighbory[i];
            if(isvalid(nx, ny) && depth[nx][ny] == 0)
            {
                if(a[x][y] == a[nx][ny])
                {
                    depth[nx][ny] = depth[x][y];
                    q.push_front({nx, ny});
                }
                else
                {
                    depth[nx][ny] = 1 + depth[x][y];
                    q.push_back({nx, ny});
                }
            }
        }
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4044 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 11 ms 3540 KB Output is correct
5 Correct 6 ms 2004 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 560 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 824 KB Output is correct
10 Correct 4 ms 1728 KB Output is correct
11 Correct 4 ms 1492 KB Output is correct
12 Correct 7 ms 2108 KB Output is correct
13 Correct 4 ms 1976 KB Output is correct
14 Correct 5 ms 2068 KB Output is correct
15 Correct 15 ms 3944 KB Output is correct
16 Correct 16 ms 4052 KB Output is correct
17 Correct 13 ms 3936 KB Output is correct
18 Correct 10 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15948 KB Output is correct
2 Correct 67 ms 12552 KB Output is correct
3 Correct 512 ms 87796 KB Output is correct
4 Correct 130 ms 32456 KB Output is correct
5 Correct 344 ms 52940 KB Output is correct
6 Correct 843 ms 122880 KB Output is correct
7 Correct 11 ms 16596 KB Output is correct
8 Correct 13 ms 15976 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 11 ms 16368 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 73 ms 12604 KB Output is correct
14 Correct 39 ms 8672 KB Output is correct
15 Correct 35 ms 11136 KB Output is correct
16 Correct 31 ms 4940 KB Output is correct
17 Correct 172 ms 28644 KB Output is correct
18 Correct 153 ms 35424 KB Output is correct
19 Correct 134 ms 32512 KB Output is correct
20 Correct 109 ms 25420 KB Output is correct
21 Correct 290 ms 52300 KB Output is correct
22 Correct 309 ms 52956 KB Output is correct
23 Correct 348 ms 43152 KB Output is correct
24 Correct 275 ms 49404 KB Output is correct
25 Correct 715 ms 108780 KB Output is correct
26 Correct 593 ms 130536 KB Output is correct
27 Correct 786 ms 122232 KB Output is correct
28 Correct 868 ms 123100 KB Output is correct
29 Correct 834 ms 121344 KB Output is correct
30 Correct 811 ms 122340 KB Output is correct
31 Correct 637 ms 73072 KB Output is correct
32 Correct 703 ms 122672 KB Output is correct