답안 #293303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293303 2020-09-07T20:53:30 Z Osama_Alkhodairy Furniture (JOI20_furniture) C++17
100 / 100
299 ms 6520 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 3 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 4 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 3 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 4 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 146 ms 4856 KB Output is correct
13 Correct 68 ms 4216 KB Output is correct
14 Correct 260 ms 5716 KB Output is correct
15 Correct 256 ms 5880 KB Output is correct
16 Correct 257 ms 6008 KB Output is correct
17 Correct 281 ms 6264 KB Output is correct
18 Correct 288 ms 6112 KB Output is correct
19 Correct 298 ms 6392 KB Output is correct
20 Correct 253 ms 6416 KB Output is correct
21 Correct 299 ms 6520 KB Output is correct