답안 #556967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556967 2022-05-04T13:10:20 Z Jarif_Rahman Furniture (JOI20_furniture) C++17
0 / 100
5000 ms 340 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], **vulnerable = new bool*[n];

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

    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_vulnerable = [&](int x, int y){
        return valid(x, y) && vulnerable[x][y];
    };

    function<void(int, int)> make_vulnerable = [&](int x, int y){
        if(!valid(x, y)) return;
        vulnerable[x][y] = 1;
        if(is_blocked(x-1, y)) make_vulnerable(x, y-1);
        if(is_blocked(x, y-1)) make_vulnerable(x-1, y);
    };
    function<void(int, int)> block = [&](int x, int y){
        blocked[x][y] = 1;
        if(is_vulnerable(x+1, y) && valid(x+1, y-1)) make_vulnerable(x+1, y-1);
        if(is_vulnerable(x, y+1) && valid(x-1, y+1)) make_vulnerable(x-1, y+1);
        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(is_vulnerable(x, y)) return 0;
        block(x, y);
        return 1;
    };

    make_vulnerable(n-1, m-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";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 5033 ms 340 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 5033 ms 340 KB Time limit exceeded
3 Halted 0 ms 0 KB -