Submission #535872

# Submission time Handle Problem Language Result Execution time Memory
535872 2022-03-11T15:11:56 Z neennera Tracks in the Snow (BOI13_tracks) C++14
100 / 100
548 ms 122364 KB
#include<bits/stdc++.h>
using namespace std;
#define ft first
#define sd second

int N,M,ans=0;
int depth[4005][4005];
string snow[4000];
int wx[5]={-1,0,0,1}, wy[5]={0,-1,1,0};

int check(int i,int j){
    return (i>=0&&i<N&&j>=0&&j<M&&snow[i][j]!='.');
}

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

    cin >> N >> M;
    for(int i=0;i<N;i++) cin >> snow[i];

    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++)
            depth[i][j]=0;
    }

    deque<pair<int,int>> q;
    q.push_back({0,0});
    depth[0][0]=1;

    while(!q.empty()){
        int x=q.front().ft;
        int y=q.front().sd;
        q.pop_front();
        ans=max(ans,depth[x][y]);
        //cout << x << " " << y << endl;
        for(int i=0;i<4;i++){
            int nx=x+wx[i];
            int ny=y+wy[i];
            //cout << i << " : " << nx << " " << ny << endl;
            //if(snow[nx][ny]=='.'){continue;}
            if(check(nx,ny)&&depth[nx][ny]==0){
                if(snow[x][y]==snow[nx][ny]){
                    depth[nx][ny]=depth[x][y];
                    q.push_front(make_pair(nx,ny));
                }else{
                    depth[nx][ny]=depth[x][y]+1;
                    q.push_back(make_pair(nx,ny));
                }
            }
        }
    }

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3796 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 580 KB Output is correct
4 Correct 8 ms 3540 KB Output is correct
5 Correct 2 ms 2004 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 584 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 2 ms 1488 KB Output is correct
12 Correct 4 ms 2132 KB Output is correct
13 Correct 2 ms 2004 KB Output is correct
14 Correct 2 ms 2004 KB Output is correct
15 Correct 8 ms 3976 KB Output is correct
16 Correct 10 ms 3796 KB Output is correct
17 Correct 7 ms 3796 KB Output is correct
18 Correct 7 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15992 KB Output is correct
2 Correct 34 ms 13948 KB Output is correct
3 Correct 167 ms 83848 KB Output is correct
4 Correct 58 ms 28888 KB Output is correct
5 Correct 149 ms 61892 KB Output is correct
6 Correct 511 ms 96988 KB Output is correct
7 Correct 9 ms 16764 KB Output is correct
8 Correct 9 ms 16080 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 8 ms 16468 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 33 ms 14676 KB Output is correct
14 Correct 21 ms 9344 KB Output is correct
15 Correct 18 ms 10456 KB Output is correct
16 Correct 15 ms 5852 KB Output is correct
17 Correct 92 ms 32712 KB Output is correct
18 Correct 82 ms 32196 KB Output is correct
19 Correct 52 ms 30232 KB Output is correct
20 Correct 42 ms 27784 KB Output is correct
21 Correct 105 ms 64672 KB Output is correct
22 Correct 147 ms 62672 KB Output is correct
23 Correct 175 ms 53608 KB Output is correct
24 Correct 118 ms 63840 KB Output is correct
25 Correct 363 ms 84972 KB Output is correct
26 Correct 306 ms 119868 KB Output is correct
27 Correct 423 ms 122364 KB Output is correct
28 Correct 542 ms 96872 KB Output is correct
29 Correct 548 ms 93920 KB Output is correct
30 Correct 499 ms 97428 KB Output is correct
31 Correct 489 ms 66000 KB Output is correct
32 Correct 397 ms 104844 KB Output is correct