Submission #423380

#TimeUsernameProblemLanguageResultExecution timeMemory
423380milleniumEeeeFurniture (JOI20_furniture)C++17
5 / 100
5042 ms920 KiB
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define fastInp ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;

const int MAXN = 1003;

char ch[MAXN][MAXN];
int n, m;

int dp[MAXN][MAXN];
int id = 0;

bool check() {
	id++;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (i == 1 && j == 1) {
				dp[i][j] = id;
			}
			else if (ch[i][j] != '1') {
				if (i > 1) {
					dp[i][j] = max(dp[i][j], dp[i - 1][j]);
				}
				if (j > 1) {
					dp[i][j] = max(dp[i][j], dp[i][j - 1]);
				}
			}
		}
	}
	return (dp[n][m] == id);
}

signed main() {
	//fastInp;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> ch[i][j];
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int i, j;
		cin >> i >> j;
		ch[i][j] = '1';
		if (check()) {
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
			ch[i][j] = '0';
		}
	}
}
/*
1 case:
2 3
0 0 1
0 0 0
3
2 2 
2 1
1 2

2 case:
2 5
0 0 0 0 0
0 0 0 1 0
2
1 2
2 2

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...