답안 #293302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293302 2020-09-07T20:51:44 Z fake_account Furniture (JOI20_furniture) C++14
100 / 100
299 ms 6380 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){
    if(g[x][y] == 1) return;
    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 Correct 1 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 9 ms 640 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 151 ms 4856 KB Output is correct
13 Correct 68 ms 4096 KB Output is correct
14 Correct 248 ms 5752 KB Output is correct
15 Correct 250 ms 5728 KB Output is correct
16 Correct 260 ms 6040 KB Output is correct
17 Correct 280 ms 6264 KB Output is correct
18 Correct 266 ms 6092 KB Output is correct
19 Correct 296 ms 6312 KB Output is correct
20 Correct 252 ms 6380 KB Output is correct
21 Correct 299 ms 6264 KB Output is correct