Submission #292584

#TimeUsernameProblemLanguageResultExecution timeMemory
292584PajarajaFurniture (JOI20_furniture)C++17
100 / 100
3428 ms5496 KiB
#include <bits/stdc++.h> #define MAXN 1007 using namespace std; bool dpgl[MAXN][MAXN],dpdd[MAXN][MAXN],b[MAXN][MAXN]; int d[2*MAXN]; int n,m; void theboysgl(int x,int y) { if(x==n+1 || y==m+1 || !dpgl[x][y] || !((x==1 || !dpgl[x-1][y]) && (y==1 || !dpgl[x][y-1]))) return; if(dpdd[x][y]) d[x+y]--; dpgl[x][y]=false; theboysgl(x+1,y); theboysgl(x,y+1); } void theboysdd(int x,int y) { if(x==0 || y==0 || !dpdd[x][y] || !((x==n || !dpdd[x+1][y]) && (y==m || !dpdd[x][y+1]))) return; if(dpgl[x][y]) d[x+y]--; dpdd[x][y]=false; theboysdd(x-1,y); theboysdd(x,y-1); } int main() { cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>b[i][j]; dpgl[1][1]=true; dpdd[n][m]=1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if((i!=1 || j!=1) && !b[i][j]) dpgl[i][j]=dpgl[i-1][j] || dpgl[i][j-1]; for(int i=n;i>=1;i--) for(int j=m;j>=1;j--) if((i!=n || j!=m) && !b[i][j]) dpdd[i][j]=dpdd[i+1][j] || dpdd[i][j+1]; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(dpgl[i][j] && dpdd[i][j]) d[i+j]++; int q; cin>>q; while(q--) { int x,y; cin>>x>>y; if(d[x+y]==1 && dpdd[x][y] && dpgl[x][y]) {cout<<"0\n"; continue;} cout<<"1\n"; if(dpdd[x][y] && dpgl[x][y]) d[x+y]--; dpdd[x][y]=dpgl[x][y]=false; theboysgl(x+1,y); theboysgl(x,y+1); theboysdd(x-1,y); theboysdd(x,y-1); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...