Submission #101619

# Submission time Handle Problem Language Result Execution time Memory
101619 2019-03-19T05:20:43 Z ShaneOng Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1078 ms 119328 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;

int h,w,dist[4009][4009],dx[]={0,1,0,-1},dy[]={1,0,-1,0},ans;
char grid[4009][4009];

int main(){
    scanf("%d%d",&h,&w);
    for(int x=0;x<h;x++)
        scanf("%s",&grid[x]);
    for(int x=0;x<h;x++)
        for(int y=0;y<w;y++)
            dist[x][y]=-1;
    deque<ii> dq;
    dq.push_front(ii(0,0));
    dist[0][0]=0;
    while(!dq.empty()){
        int ux=dq.front().first,uy=dq.front().second;
        dq.pop_front();
        for(int i=0;i<4;i++){
            int vx=ux+dx[i],vy=uy+dy[i];
            if(vx>=0&&vx<h&&vy>=0&&vy<w)
                if(grid[vx][vy]!='.'){
                    int val=(grid[ux][uy]!=grid[vx][vy]);
                    if(dist[vx][vy]==-1){
                        dist[vx][vy]=dist[ux][uy]+val;
                        //printf("%d,%d:%d\n",vx,vy,dist[vx][vy]);
                        ans=max(dist[vx][vy],ans);
                        if(val==0)
                            dq.push_front(ii(vx,vy));
                        else
                            dq.push_back(ii(vx,vy));
                    }
                }
        }
    }
    printf("%d\n",ans+1);
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:11:28: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[4009]' [-Wformat=]
         scanf("%s",&grid[x]);
                    ~~~~~~~~^
tracks.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&h,&w);
     ~~~~~^~~~~~~~~~~~~~
tracks.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",&grid[x]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5248 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 12 ms 4992 KB Output is correct
5 Correct 6 ms 2944 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 6 ms 1280 KB Output is correct
10 Correct 7 ms 2560 KB Output is correct
11 Correct 5 ms 2176 KB Output is correct
12 Correct 9 ms 2944 KB Output is correct
13 Correct 7 ms 2944 KB Output is correct
14 Correct 5 ms 2944 KB Output is correct
15 Correct 16 ms 5376 KB Output is correct
16 Correct 19 ms 5248 KB Output is correct
17 Correct 14 ms 5120 KB Output is correct
18 Correct 17 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 30820 KB Output is correct
2 Correct 55 ms 16476 KB Output is correct
3 Correct 250 ms 78812 KB Output is correct
4 Correct 88 ms 29944 KB Output is correct
5 Correct 152 ms 59128 KB Output is correct
6 Correct 997 ms 93264 KB Output is correct
7 Correct 36 ms 32256 KB Output is correct
8 Correct 28 ms 30848 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 31 ms 31608 KB Output is correct
12 Correct 4 ms 1664 KB Output is correct
13 Correct 52 ms 16384 KB Output is correct
14 Correct 30 ms 11136 KB Output is correct
15 Correct 40 ms 12152 KB Output is correct
16 Correct 24 ms 6048 KB Output is correct
17 Correct 137 ms 32248 KB Output is correct
18 Correct 139 ms 31864 KB Output is correct
19 Correct 101 ms 30072 KB Output is correct
20 Correct 78 ms 27768 KB Output is correct
21 Correct 183 ms 61228 KB Output is correct
22 Correct 203 ms 59128 KB Output is correct
23 Correct 278 ms 49400 KB Output is correct
24 Correct 192 ms 60664 KB Output is correct
25 Correct 540 ms 78848 KB Output is correct
26 Correct 1004 ms 119328 KB Output is correct
27 Correct 982 ms 104532 KB Output is correct
28 Correct 1018 ms 93368 KB Output is correct
29 Correct 1078 ms 90424 KB Output is correct
30 Correct 1043 ms 96080 KB Output is correct
31 Correct 825 ms 63812 KB Output is correct
32 Correct 943 ms 102840 KB Output is correct