제출 #319976

#제출 시각아이디문제언어결과실행 시간메모리
319976jamezzzFurniture (JOI20_furniture)C++14
100 / 100
462 ms13028 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, q, x, y, c[2005];
bool r[1005][1005];

void dfs(int x, int y);

void push(int x, int y){
    if (r[x][y]){
        r[x][y] = false;
        --c[x + y];
        dfs(x, y);
    }
}

int add(int x, int y){
    if (!r[x][y]) return 1; //no path through (x, y)
    if (c[x + y] == 1) return 0;
    push(x, y);
    return 1;
}

void dfs(int x, int y){
    if (!r[x - 1][y + 1]){
        push(x - 1, y);
        push(x, y + 1);
    }
    if (!r[x + 1][y - 1]){
        push(x, y - 1);
        push(x + 1, y);
    }
}



int main(){
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= m; ++j){
            r[i][j] = true;
            ++c[i + j];
        }
    }

    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= m; ++j){
            scanf("%d", &x);
            if (x == 1) add(i, j);
        }
    }

    scanf("%d", &q);
    for (int i = 0; i < q; ++i){
        scanf("%d%d", &x, &y);
        printf("%d\n", add(x, y));
    }
}

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

furniture.cpp: In function 'int main()':
furniture.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
furniture.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~
furniture.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
furniture.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...