Submission #424825

# Submission time Handle Problem Language Result Execution time Memory
424825 2021-06-12T10:41:22 Z abdzag Furniture (JOI20_furniture) C++17
0 / 100
5000 ms 332 KB
#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 1e15;

using namespace std;

ll n, m;
vector<vector<ll>> grid;
void fix(ll x, ll y) {
	if (x < 0 || x >= n || y < 0 || y >= m)return;
	if (grid[x][y])return;
	if (x + 1 < n) {
		if (grid[x + 1][y]) {
			if (y + 1 < m) {
				if (grid[x][y + 1])grid[x][y] = 1;
			}
			else grid[x][y] = 1;
		}
	}
	else if (y + 1 < m) {
		if (grid[x][y + 1])grid[x][y] =1;
	}
	else grid[x][y] = 1;
	fix(x - 1, y);
	fix(x, y - 1);
}
void update(ll x,ll y) {
	if (x > 0) {
		if (y + 1 < m) {
			if (!grid[x - 1][y + 1])grid[x][y] =1;
		}
	}
	if (x+1 < n) {
		if (y> 0) {
			if (!grid[x +1][y-1])grid[x][y] = 1;
		}
	}
	fix(x - 1, y);
	fix(x, y - 1);
	return;
}
int main() {
	cin.sync_with_stdio(false);
	cin >> n>>m;
	grid.resize(n, vector<ll>(m));
	rep(i, 0, n) {
		rep(j, 0, m) {
			ll a;
			cin >> a;
			if (a) {
				update(i, j);
			}
		}
	}
	ll q;
	cin >> q;
	rep(i, 0, q) {
		ll x, y;
		cin >> x >> y;
		x--, y--;
		update(x, y);
		cout << grid[x][y] << endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 5069 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5069 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -