답안 #424830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424830 2021-06-12T10:43:41 Z abdzag Furniture (JOI20_furniture) C++17
0 / 100
2 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;
	if (grid[x][y]) {
		fix(x - 1, y);
		fix(x, y - 1);
	}
	return;
}
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;
		}
	}
	if (grid[x][y]) {
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -