Submission #742786

# Submission time Handle Problem Language Result Execution time Memory
742786 2023-05-16T23:46:41 Z ToniB Furniture (JOI20_furniture) C++17
0 / 100
2 ms 724 KB
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
typedef pair<int, int> pii;
const int MAXN = 1001;

int n, m, q, c[MAXN][MAXN], ans[MAXN * MAXN];
bool flag[MAXN][MAXN], bio[MAXN][MAXN], vis[MAXN][MAXN];
priority_queue<pair<pii, pii> > pq;

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			cin >> bio[i][j];
//			c[i][j] = n * m + i * m + j;
		}
	}
	cin >> q;
	for(int i = 1; i <= q; ++i){
		int x, y;
		cin >> x >> y, --x, --y;
		c[x][y] = i;
	}
	pq.push({{0, c[0][0]}, {0, 0}});
	bio[0][0] = 1;
	while(!pq.empty()){
		int x = pq.top().Y.X, y = pq.top().Y.Y;
		pq.pop();
		if(x != n - 1 && !bio[x + 1][y]){
			bio[x + 1][y] = 1;
			pq.push({{x + y + 1, c[x + 1][y]}, {x + 1, y}});
			flag[x + 1][y] = 0;
		}
		if(y != m - 1 && !bio[x][y + 1]){
			bio[x][y + 1] = 1;
			pq.push({{x + y + 1, c[x][y + 1]}, {x, y + 1}});
			flag[x][y + 1] = 1;
		}
	}
	int i = n - 1, j = m - 1;
	while(i || j){
		if(flag[i][j]) --j;
		else --i;
		vis[i][j] = 1;
	}
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			if(c[i][j] < n * m) ans[c[i][j]] = vis[i][j];
		}
	}
	for(int i = 1; i <= q; ++i){
		cout << !ans[i] << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -