Submission #423380

# Submission time Handle Problem Language Result Execution time Memory
423380 2021-06-11T04:38:13 Z milleniumEeee Furniture (JOI20_furniture) C++17
5 / 100
5000 ms 920 KB
#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 time Memory Grader output
1 Correct 12 ms 588 KB Output is correct
2 Correct 71 ms 716 KB Output is correct
3 Correct 187 ms 716 KB Output is correct
4 Correct 325 ms 764 KB Output is correct
5 Correct 354 ms 792 KB Output is correct
6 Correct 452 ms 920 KB Output is correct
7 Correct 334 ms 804 KB Output is correct
8 Correct 310 ms 912 KB Output is correct
9 Correct 308 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 588 KB Output is correct
2 Correct 71 ms 716 KB Output is correct
3 Correct 187 ms 716 KB Output is correct
4 Correct 325 ms 764 KB Output is correct
5 Correct 354 ms 792 KB Output is correct
6 Correct 452 ms 920 KB Output is correct
7 Correct 334 ms 804 KB Output is correct
8 Correct 310 ms 912 KB Output is correct
9 Correct 308 ms 792 KB Output is correct
10 Execution timed out 5042 ms 744 KB Time limit exceeded
11 Halted 0 ms 0 KB -