Submission #42411

# Submission time Handle Problem Language Result Execution time Memory
42411 2018-02-26T18:19:40 Z Hassoony Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1423 ms 49620 KB
#include<bits/stdc++.h>
#include<unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double D;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=4002;
int n,m,ans;
bool vis[MX][MX];
char a[MX][MX],c;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%s",&a[i]);
    queue<pair<int,int> >q[2];
    int node=0;
    if(a[0][0]=='.'){
        puts("0");
        return 0;
    }
    q[node].push({0,0});
    while(!q[node].empty()){
        ans++;
        while(!q[node].empty()){
            int x=q[node].front().first,y=q[node].front().second;q[node].pop();
            if(vis[x][y])continue;
            vis[x][y]=1;
            for(int i=0;i<4;i++){
                int nx=dx[i]+x,ny=dy[i]+y;
                if(nx>=n||ny>=m||nx<0||ny<0||vis[nx][ny]||a[nx][ny]=='.')continue;
                if(a[nx][ny]==a[x][y])q[node].push({nx,ny});
                else q[node^1].push({nx,ny});
            }
        }
        node^=1;
    }
    cout<<ans<<endl;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:18:41: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[4002]' [-Wformat=]
     for(int i=0;i<n;i++)scanf("%s",&a[i]);
                                         ^
tracks.cpp:17:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
tracks.cpp:18:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++)scanf("%s",&a[i]);
                                          ^
# Verdict Execution time Memory Grader output
1 Correct 25 ms 4216 KB Output is correct
2 Correct 2 ms 4216 KB Output is correct
3 Correct 2 ms 4216 KB Output is correct
4 Correct 14 ms 4384 KB Output is correct
5 Correct 6 ms 4384 KB Output is correct
6 Correct 2 ms 4384 KB Output is correct
7 Correct 2 ms 4384 KB Output is correct
8 Correct 2 ms 4384 KB Output is correct
9 Correct 2 ms 4384 KB Output is correct
10 Correct 5 ms 4384 KB Output is correct
11 Correct 5 ms 4384 KB Output is correct
12 Correct 10 ms 4384 KB Output is correct
13 Correct 5 ms 4384 KB Output is correct
14 Correct 5 ms 4384 KB Output is correct
15 Correct 20 ms 4460 KB Output is correct
16 Correct 23 ms 4460 KB Output is correct
17 Correct 13 ms 4460 KB Output is correct
18 Correct 15 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 30444 KB Output is correct
2 Correct 67 ms 30444 KB Output is correct
3 Correct 278 ms 31980 KB Output is correct
4 Correct 82 ms 31980 KB Output is correct
5 Correct 160 ms 31980 KB Output is correct
6 Correct 1423 ms 49620 KB Output is correct
7 Correct 29 ms 49620 KB Output is correct
8 Correct 28 ms 49620 KB Output is correct
9 Correct 3 ms 49620 KB Output is correct
10 Correct 2 ms 49620 KB Output is correct
11 Correct 28 ms 49620 KB Output is correct
12 Correct 3 ms 49620 KB Output is correct
13 Correct 72 ms 49620 KB Output is correct
14 Correct 40 ms 49620 KB Output is correct
15 Correct 26 ms 49620 KB Output is correct
16 Correct 36 ms 49620 KB Output is correct
17 Correct 187 ms 49620 KB Output is correct
18 Correct 95 ms 49620 KB Output is correct
19 Correct 75 ms 49620 KB Output is correct
20 Correct 74 ms 49620 KB Output is correct
21 Correct 179 ms 49620 KB Output is correct
22 Correct 166 ms 49620 KB Output is correct
23 Correct 359 ms 49620 KB Output is correct
24 Correct 152 ms 49620 KB Output is correct
25 Correct 401 ms 49620 KB Output is correct
26 Correct 698 ms 49620 KB Output is correct
27 Correct 965 ms 49620 KB Output is correct
28 Correct 1405 ms 49620 KB Output is correct
29 Correct 1362 ms 49620 KB Output is correct
30 Correct 1155 ms 49620 KB Output is correct
31 Correct 1122 ms 49620 KB Output is correct
32 Correct 767 ms 49620 KB Output is correct