Submission #742777

# Submission time Handle Problem Language Result Execution time Memory
742777 2023-05-16T22:58:34 Z ToniB Furniture (JOI20_furniture) C++14
0 / 100
4 ms 2004 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;
set<pii> s;

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			cin >> bio[i][j];
			s.insert({i, j});
			c[i][j] = n * m + i * m + j;
		}
	}
	cin >> q;
	for(int i = 0; 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(vis[i][j]) assert(s.find({i, j}) == s.end());
			if(c[i][j] < n * m) ans[c[i][j]] = vis[i][j];
		}
	}
	for(int i = 0; i < q; ++i){
		cout << !ans[i] << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -