Submission #1326017

#TimeUsernameProblemLanguageResultExecution timeMemory
1326017JuanJLFurniture (JOI20_furniture)C++20
5 / 100
811 ms7844 KiB
#include <bits/stdc++.h>

#define fst first
#define snd second
#define pb push_back
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),end()
#define forn(i,a,b) for(int i = a; i<b; i++)
#define mset(a,v) memset(a,v,sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long ll;

const int MAXN = 100+5;

vector<pair<ll,ll>> oper = {{0,1},{1,0}};

ll n,m;
vector<vector<ll>> mapa;
bool vis[MAXN][MAXN];

void dfs(ll i, ll j){
	if(vis[i][j]) return;
	vis[i][j]=true;
	
	for(auto o:oper) if(i+o.fst<n && i+o.fst>=0 && j+o.snd<m && j+o.snd>=0){
		if(mapa[i+o.fst][j+o.snd]==0) dfs(i+o.fst,j+o.snd);
	}
}

int main(){
	cin>>n>>m;
	mapa.clear();
	mapa.resize(n,vector<ll>(m));
	forn(i,0,n){
		forn(j,0,m){
			cin>>mapa[i][j];
		}
	}

	ll q; cin>>q;
	forn(i,0,q){
		ll x,y; cin>>x>>y; x--; y--;
		if(mapa[x][y]!=1){
			mapa[x][y]=1;
			mset(vis,false);
			dfs(0,0);
			if(!vis[n-1][m-1]) mapa[x][y]=0, cout<<0<<'\n';
			else cout<<1<<'\n';
		}else{
			cout<<0<<'\n';
		}
	}
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...