제출 #101561

#제출 시각아이디문제언어결과실행 시간메모리
101561dantoh000Tracks in the Snow (BOI13_tracks)C++14
47.50 / 100
2097 ms31864 KiB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
int main(){
    int h,w;
    scanf("%d%d",&h,&w);
    char grid[h][w];
    int nonempty = 0;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            scanf(" %c",&grid[i][j]);
            if (grid[i][j] != '.') nonempty++;
        }
    }
    int num = 0;
    bool vis[h][w];
    int ans = 0;
    while (num != nonempty){
        char a = grid[0][0];
        char b = a ^ 'F' ^ 'R';
        memset(vis,0,sizeof(vis));
        queue<ii> q;
        q.push(ii(0,0));
        vis[0][0] = 1;
        grid[0][0] = b;
        num = 1;
        while(q.size()){
            ii cur = q.front(); q.pop();
            int x = cur.first, y = cur.second;
            for (int k = 0; k < 4; k++){
                int nx = x + dx[k], ny = y + dy[k];
                if (nx >= 0 && nx < h && ny >= 0 && ny < w){
                    if (grid[nx][ny] == a && !vis[nx][ny]){
                        grid[nx][ny] = b;
                        vis[nx][ny] = 1;
                        num++;
                        q.push(ii(nx,ny));
                    }
                }
            }
        }
        ans++;
    }
    printf("%d",ans);


}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:7: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:12:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c",&grid[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...