답안 #293223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293223 2020-09-07T19:12:57 Z Osama_Alkhodairy Furniture (JOI20_furniture) C++17
0 / 100
2 ms 768 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 1005;

int n, m, q, g[N][N], s[2 * N];

void gogo(int x, int y);
void go(int x, int y){
    if((x == 1 && y == 1) || (x == n && y == m)) return;
    if(g[x][y] == 1) return;
    if((g[x - 1][y] && g[x][y - 1]) || (g[x + 1][y] && g[x][y + 1])){
        gogo(x, y);
    }
}
void gogo(int x, int y){
    g[x][y] = 1;
    s[x + y]--;
    go(x - 1, y);
    go(x, y - 1);
    go(x + 1, y);
    go(x, y + 1);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int j = 0 ; j <= m + 1 ; j++){
        g[0][j] = g[n + 1][j] = 1;
    }
    for(int i = 0 ; i <= n + 1 ; i++){
        g[i][0] = g[i][m + 1] = 1;
    }
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            s[i + j]++;
        }
    }
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            int x;
            cin >> x;
            if(x) gogo(i, j);
        }
    }
    cin >> q;
    while(q--){
        int x, y;
        cin >> x >> y;
        if(g[x][y]) cout << "1\n";
        else if(s[x + y] == 1) cout << "0\n";
        else{
            cout << "1\n";
            gogo(x, y);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Incorrect 2 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Incorrect 2 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -