Submission #1013901

#TimeUsernameProblemLanguageResultExecution timeMemory
1013901BaytoroFurniture (JOI20_furniture)C++17
100 / 100
1461 ms16256 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fr first #define sc second //#define int ll #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() int n,m; int a[1005][1005],diag[100005]; vector<int> dx={1,-1,0,0}, dy={0,0,1,-1}; void bfs(int x, int y) { if(a[x][y]==1) return; diag[x+y]--; a[x][y]=1; for(int i=0;i<4;i++) { int X=x+dx[i],Y=y+dy[i]; if(!a[X][Y] && ((a[X-1][Y] && a[X][Y-1] && !(X==1 && Y==1)) || (a[X+1][Y] && a[X][Y+1] && !(X==n && Y==m)))) { bfs(X,Y); } } } void solve() { cin>>n>>m; vector<pair<int,int>> v; memset(a,1,sizeof a); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { //cin>>a[i][j]; int x;cin>>x; if(x) v.pb({i,j}); diag[i+j]++; a[i][j]=0; } } for(auto it: v) bfs(it.fr,it.sc); /*for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cout<<a[i][j]<<' '; } cout<<endl; }*/ int q;cin>>q; while(q--) { int x,y;cin>>x>>y; if(a[x][y]) { cout<<1<<endl; continue; } if(diag[x+y]==1) { cout<<0<<endl; continue; } cout<<1<<endl; bfs(x,y); } } signed main(){ int t=1;//cin>>t; while(t--){ solve(); } } //#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...