Submission #556967

#TimeUsernameProblemLanguageResultExecution timeMemory
556967Jarif_RahmanFurniture (JOI20_furniture)C++17
0 / 100
5033 ms340 KiB
#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"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...