Submission #361733

#TimeUsernameProblemLanguageResultExecution timeMemory
361733Bill_00Furniture (JOI20_furniture)C++14
5 / 100
346 ms22252 KiB
#include <bits/stdc++.h> #define pb push_back #define ff first #define ss second #define N 1001 typedef long long ll; using namespace std; bool r[N][N]; int c[N][N]; int a[N*2]; vector<pair<int,int> >v; void detect(int x,int y){ r[x][y]=1; a[x+y]--; if(r[x+1][y-1]==1){ if(r[x][y-1]==0){ detect(x,y-1); } if(r[x+1][y]==0){ detect(x+1,y); } } if(r[x-1][y+1]==1){ if(r[x-1][y]==0){ detect(x-1,y); } if(r[x][y+1]==0){ detect(x,y+1); } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin >> c[i][j]; if(c[i][j]==1) v.pb({i,j}); a[i+j]++; } } for(int i=0;i<=n+1;i++){ r[i][0]=1; r[i][m+1]=1; } for(int i=0;i<=m+1;i++){ r[0][i]=1; r[n+1][i]=1; } for(pair<int,int>fur:v){ if(r[fur.ff][fur.ss]==0) detect(fur.ff,fur.ss); } int q; cin >> q; while(q--){ int x,y; cin >> x >> y; if(r[x][y]==1){ cout << 1 << '\n'; } else{ if(a[x+y]>1){ cout << 1 << '\n'; detect(x,y); } else cout << 0 << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...