Submission #704621

# Submission time Handle Problem Language Result Execution time Memory
704621 2023-03-02T12:56:24 Z Abrar_Al_Samit Furniture (JOI20_furniture) C++17
0 / 100
511 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;


int dx[] {1, -1, 0, 0};
int dy[] {0, 0, 1, -1};
void PlayGround() {
	int n, m;
	cin>>n>>m;
	int a[n+1][m+1];
	bool vis[n+1][m+1];
	for(int i=1; i<=n; ++i) {
		for(int j=1; j<=m; ++j) {
			cin>>a[i][j];
		}
	}	

	auto valid = [&] (int x, int y) {
		return min(x, y)>=1 && x<=n  && y<=m; 
	};

	int q;
	cin>>q;
	while(q--) {
		int x, y;
		cin>>x>>y;

		a[x][y] = 1;
		memset(vis, 0, sizeof vis);

		queue<pair<int,int>>q;
		q.emplace(1, 1);
		while(!q.empty()) {
			auto [x, y] = q.front();
			q.pop();
			if(vis[x][y]) continue;

			for(int k=0; k<4; ++k) {
				int nx = x + dx[k], ny = y + dy[k];
				if(valid(nx, ny)) {
					q.emplace(nx, ny);
				}
			}
		}
		if(!vis[n][m]) {
			cout<<"0\n";
			a[x][y] = 0;
		} else {
			cout<<"1\n";
		}
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 511 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 511 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -