제출 #1326026

#제출 시각아이디문제언어결과실행 시간메모리
1326026JuanJLFurniture (JOI20_furniture)C++20
0 / 100
2 ms824 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(),x.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; #ifdef D #define debug(x) cout << "debug -> "<< x #else #define debug(x) //nothing #endif const int MAXN = 100+5; vector<pair<ll,ll>> oper = {{0,1},{1,0}}; vector<pair<ll,ll>> roper = {{0,-1},{-1,0}}; ll n,m; vector<vector<ll>> mapa; bool vis[MAXN][MAXN]; vector<pair<ll,ll>> llega[MAXN][MAXN]; bool dfs(ll i, ll j){ if(vis[i][j]) return SZ(llega[i][j])>0; vis[i][j]=true; if(i==n-1 && j==m-1) llega[i][j]={{-1,-1}}; for(auto o:oper) if(i+o.fst<n && j+o.snd<m){ if(mapa[i+o.fst][j+o.snd]==0 && dfs(i+o.fst,j+o.snd)){ llega[i][j].pb({i+o.fst,j+o.snd}); } } return SZ(llega[i][j])>0; } bool yes=false; void rdfs(ll i, ll j){ if(i==0 && j==0){ yes=true; return; } debug(i<<" "<<j<<'\n'); forn(k,0,2){ for(auto o:roper) if(i+o.fst>=0 && j+o.snd>=0){ if(k>=SZ(llega[i+o.fst][j+o.snd])) continue; if(llega[i+o.fst][j+o.snd][k]==pair<ll,ll>{i,j}){ if(SZ(llega[i+o.fst][j+o.snd])==1){ rdfs(i+o.fst,j+o.snd); } if(!yes){ auto it = lower_bound(ALL(llega[i+o.fst][j+o.snd]),pair<ll,ll>{i,j}); llega[i+o.fst][j+o.snd].erase(it); } } } } } int main(){ FIN; cin>>n>>m; mapa.clear(); mapa.resize(n,vector<ll>(m)); forn(i,0,n){ forn(j,0,m){ cin>>mapa[i][j]; } } dfs(0,0); 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); forn(I,0,n) forn(J,0,n) llega[I][J].clear(); if(!dfs(0,0)) mapa[x][y]=0, cout<<0<<'\n'; else cout<<1<<'\n';*/ yes=false; rdfs(x,y); if(yes){ 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...