Submission #1095849

# Submission time Handle Problem Language Result Execution time Memory
1095849 2024-10-03T10:29:19 Z _8_8_ Furniture (JOI20_furniture) C++17
100 / 100
218 ms 20052 KB
#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
const int  N = 1e3 + 12, MOD = (int)1e9 + 7;

int n, m, a[N][N], c[N * 2], r[N][N];

bool ok(int x, int y) {
    return min(x, y) >= 0 && x <= n + 1 && y <= m + 1 && a[x][y];
}
void make(int x, int y) {
    if(a[x][y]) return;
    a[x][y] = 1;   
    c[x + y]--;
    if(a[x + 1][y - 1]) {
        if(y - 1 >= 1) make(x, y - 1);
        if(x + 1 <= n) make(x + 1, y);
    }
    if(a[x - 1][y + 1]) {
        if(x - 1 >= 1) make(x - 1, y);
        if(y + 1 <= m) make(x, y + 1);
    }
}
void test() {
    cin >> n >> m;
    for(int i = 0; i <= m + 1; i++) {
        a[0][i] = a[n + 1][i] = 1;
    }
    for(int i = 0; i <= n + 1; i++) {
        a[i][0] = a[i][m + 1] = 1;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            c[i + j]++;
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> r[i][j];
        }
    }

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(r[i][j]) {
                make(i, j);
            }
        }
    }
    // return;
    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        if(a[x][y]) {
            cout << 1 << '\n';
        } else {
            if(c[x + y] > 1) {
                cout << 1 << '\n';
                make(x, y);
            } else {
                cout << 0 << '\n';
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); 

    int t = 1; 
    // cin >> t;
    
    while(t--) 
        test();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1216 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1244 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1368 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1216 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1244 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 3 ms 1368 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 6 ms 1132 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 95 ms 12976 KB Output is correct
13 Correct 45 ms 9812 KB Output is correct
14 Correct 176 ms 17224 KB Output is correct
15 Correct 193 ms 17492 KB Output is correct
16 Correct 179 ms 18512 KB Output is correct
17 Correct 186 ms 19408 KB Output is correct
18 Correct 190 ms 19028 KB Output is correct
19 Correct 192 ms 20048 KB Output is correct
20 Correct 180 ms 20052 KB Output is correct
21 Correct 218 ms 19796 KB Output is correct