Submission #892446

# Submission time Handle Problem Language Result Execution time Memory
892446 2023-12-25T10:53:50 Z tnknguyen_ Tracks in the Snow (BOI13_tracks) C++14
100 / 100
753 ms 217692 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' 
/**
* IDEA:
*/

const int sz = 4e3 + 5;
int m, n;
int a[sz][sz], vi[sz][sz], d[sz][sz];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

bool valid(int x, int y){
    return (x >= 1 && x <= m && y >= 1 && y <= n);
}

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

    // freopen("main.inp","r",stdin);
    // freopen("main.out","w",stdout);

    cin>>m>>n;

    for(int i=1;i<=m;++i){
        for(int j=1;j<=n;++j){
            char c;
            cin>>c;
            if(c == '.'){
                a[i][j] = -1;
                continue;
            }
            if(c == 'F'){
                a[i][j] = 1;
            }
            else{
                a[i][j] = 2;
            }
        }
    }

    deque<pair<int,int>> q;
    q.push_front({1, 1});
    vi[1][1] = 1;
    d[1][1] = 1;

    int ans = 0;
    while(q.size()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop_front();

        ans = max(ans, d[x][y]);

        for(int i=0;i<4;++i){
            int u = x + dx[i];
            int v = y + dy[i];
            int c = (a[x][y] != a[u][v]);
            if(valid(u, v) && !vi[u][v] && a[u][v] != -1){
                d[u][v] = d[x][y] + c;
                vi[u][v] = 1;
                if(!c){
                    q.push_front({u, v});
                }
                else{
                    q.push_back({u, v});
                }
            }
        }
    }

    cout<<ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21340 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 10 ms 21344 KB Output is correct
5 Correct 4 ms 15964 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 3 ms 13660 KB Output is correct
11 Correct 3 ms 11356 KB Output is correct
12 Correct 6 ms 15964 KB Output is correct
13 Correct 4 ms 15964 KB Output is correct
14 Correct 4 ms 15964 KB Output is correct
15 Correct 11 ms 21208 KB Output is correct
16 Correct 13 ms 21568 KB Output is correct
17 Correct 11 ms 21340 KB Output is correct
18 Correct 8 ms 21340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 140884 KB Output is correct
2 Correct 45 ms 51280 KB Output is correct
3 Correct 296 ms 167964 KB Output is correct
4 Correct 89 ms 84712 KB Output is correct
5 Correct 161 ms 130772 KB Output is correct
6 Correct 753 ms 202964 KB Output is correct
7 Correct 21 ms 141916 KB Output is correct
8 Correct 20 ms 140892 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 21 ms 141148 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 45 ms 51256 KB Output is correct
14 Correct 29 ms 38356 KB Output is correct
15 Correct 32 ms 42696 KB Output is correct
16 Correct 20 ms 19548 KB Output is correct
17 Correct 109 ms 84236 KB Output is correct
18 Correct 107 ms 90956 KB Output is correct
19 Correct 107 ms 84816 KB Output is correct
20 Correct 69 ms 74480 KB Output is correct
21 Correct 165 ms 131264 KB Output is correct
22 Correct 158 ms 130900 KB Output is correct
23 Correct 218 ms 109964 KB Output is correct
24 Correct 168 ms 128932 KB Output is correct
25 Correct 505 ms 188436 KB Output is correct
26 Correct 745 ms 217692 KB Output is correct
27 Correct 657 ms 214384 KB Output is correct
28 Correct 715 ms 202756 KB Output is correct
29 Correct 713 ms 200276 KB Output is correct
30 Correct 691 ms 205260 KB Output is correct
31 Correct 429 ms 154708 KB Output is correct
32 Correct 662 ms 208728 KB Output is correct