답안 #101566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101566 2019-03-19T04:31:03 Z errorgorn Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1550 ms 781188 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int,int> ii;
int r,c;
char arr[4005][4005];
bool pushed[4005][4005];
queue<ii> q;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
void print(){
    for (int x=1;x<=r;x++){
        for (int y=1;y<=c;y++){
            printf("%c",arr[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}
void dfs(int i,int j,char a){
    for (int x=0;x<4;x++){
        if (i+dx[x]<1 || i+dx[x]>r || j+dy[x]<1 || j+dy[x]>c) continue;
        if (arr[i+dx[x]][j+dy[x]]==a){
            arr[i+dx[x]][j+dy[x]]='.';
            dfs(i+dx[x],j+dy[x],a);
        }
        else if (arr[i+dx[x]][j+dy[x]]!='.'){
            if (!pushed[i+dx[x]][j+dy[x]])q.push(ii(i+dx[x],j+dy[x])),pushed[i+dx[x]][j+dy[x]]=true;
        }
    }
}
int main(){
    char curr_animal='?';
    int ans=0;
    //freopen("input.txt","r",stdin);
    scanf("%d%d",&r,&c);
    for (int x=1;x<=r;x++){
        getchar();
        for (int y=1;y<=c;y++){
            arr[x][y]=getchar();
        }
    }
    q.push(ii(1,1));
    q.push(ii(r,c));
    int a,b;
    while (!q.empty()){
        a=q.front().first,b=q.front().second,q.pop();
        //printf("%d %d\n",a,b);
        if (arr[a][b]=='.') continue;
        if (curr_animal!=arr[a][b]) curr_animal=arr[a][b],ans++;
        arr[a][b]='.';
        dfs(a,b,curr_animal);
    }
    printf("%d\n",ans);
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&r,&c);
     ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 4352 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 15 ms 5120 KB Output is correct
5 Correct 3 ms 2560 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 7 ms 2304 KB Output is correct
11 Correct 6 ms 2176 KB Output is correct
12 Correct 9 ms 2688 KB Output is correct
13 Correct 7 ms 2588 KB Output is correct
14 Correct 6 ms 2560 KB Output is correct
15 Correct 19 ms 4352 KB Output is correct
16 Correct 23 ms 4352 KB Output is correct
17 Correct 15 ms 4224 KB Output is correct
18 Correct 16 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25208 KB Output is correct
2 Correct 64 ms 10248 KB Output is correct
3 Correct 342 ms 32180 KB Output is correct
4 Correct 103 ms 15292 KB Output is correct
5 Correct 274 ms 24164 KB Output is correct
6 Correct 960 ms 75780 KB Output is correct
7 Correct 27 ms 26216 KB Output is correct
8 Correct 31 ms 25208 KB Output is correct
9 Correct 5 ms 740 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 25 ms 23928 KB Output is correct
12 Correct 4 ms 1664 KB Output is correct
13 Correct 64 ms 10232 KB Output is correct
14 Correct 41 ms 7516 KB Output is correct
15 Correct 37 ms 8192 KB Output is correct
16 Correct 29 ms 3676 KB Output is correct
17 Correct 151 ms 16376 KB Output is correct
18 Correct 131 ms 16348 KB Output is correct
19 Correct 109 ms 15344 KB Output is correct
20 Correct 85 ms 14300 KB Output is correct
21 Correct 206 ms 24976 KB Output is correct
22 Correct 234 ms 24124 KB Output is correct
23 Correct 281 ms 20368 KB Output is correct
24 Correct 164 ms 22520 KB Output is correct
25 Correct 484 ms 32184 KB Output is correct
26 Correct 1550 ms 781188 KB Output is correct
27 Correct 924 ms 234784 KB Output is correct
28 Correct 853 ms 75788 KB Output is correct
29 Correct 877 ms 70492 KB Output is correct
30 Correct 1027 ms 115080 KB Output is correct
31 Correct 792 ms 26432 KB Output is correct
32 Correct 1122 ms 251252 KB Output is correct