Submission #704623

# Submission time Handle Problem Language Result Execution time Memory
704623 2023-03-02T12:59:39 Z Abrar_Al_Samit Furniture (JOI20_furniture) C++17
0 / 100
142 ms 348 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;
			vis[x][y] = true;

			for(int k=0; k<4; ++k) {
				int nx = x + dx[k], ny = y + dy[k];
				if(valid(nx, ny) && a[nx][ny]==0) {
					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 Correct 62 ms 340 KB Output is correct
2 Incorrect 142 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 340 KB Output is correct
2 Incorrect 142 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -