Submission #557360

# Submission time Handle Problem Language Result Execution time Memory
557360 2022-05-05T08:04:14 Z Jarif_Rahman Furniture (JOI20_furniture) C++17
100 / 100
317 ms 14940 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m; cin >> n >> m;
    bool **s = new bool*[n], **blocked = new bool*[n], **nice = new bool*[n];

    for(int i = 0; i < n; i++){
        s[i] = new bool[m], blocked[i] = new bool[m], nice[i] = new bool[m];
        fill(s[i], s[i]+m, 0);
        fill(blocked[i], blocked[i]+m, 0);
        fill(nice[i], nice[i]+m, 1);
    }

    int* dig = new int[n+m-1];
    fill(dig, dig+n+m-1, 0);
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) dig[i+j]++;

    auto valid = [&](int x, int y){
        return x >= 0 && x < n && y >= 0 && y < m;
    };
    auto is_blocked = [&](int x, int y){
        return !valid(x, y) || blocked[x][y];
    };
    auto is_nice = [&](int x, int y){
        return valid(x, y) && nice[x][y];
    };

    function<void(int, int)> make_unnice = [&](int x, int y){
        if(!nice[x][y]) return;
        nice[x][y] = 0;
        dig[x+y]--;
        if(is_nice(x-1, y) && !is_nice(x-1, y+1)) make_unnice(x-1, y);
        if(is_nice(x, y-1) && !is_nice(x+1, y-1)) make_unnice(x, y-1);
    };
    function<void(int, int)> block = [&](int x, int y){
        blocked[x][y] = 1;
        make_unnice(x, y);
        if(!is_blocked(x+1, y) && is_blocked(x+1, y-1)) block(x+1, y);
        if(!is_blocked(x, y+1) && is_blocked(x-1, y+1)) block(x, y+1);
    };

    auto add = [&](int x, int y){
        if(nice[x][y] && dig[x+y] == 1) return 0;
        block(x, y);
        return 1;
    };

    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
        bool x; cin >> x;
        if(x) add(i, j);
    }

    int q; cin >> q;
    while(q--){
        int x, y; cin >> x >> y; x--, y--;
        cout << add(x, y) << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 3 ms 464 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 3 ms 464 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 440 KB Output is correct
10 Correct 11 ms 832 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 163 ms 7752 KB Output is correct
13 Correct 68 ms 4804 KB Output is correct
14 Correct 267 ms 12540 KB Output is correct
15 Correct 263 ms 12752 KB Output is correct
16 Correct 280 ms 13680 KB Output is correct
17 Correct 294 ms 14540 KB Output is correct
18 Correct 293 ms 14132 KB Output is correct
19 Correct 295 ms 14848 KB Output is correct
20 Correct 292 ms 14940 KB Output is correct
21 Correct 317 ms 14924 KB Output is correct