제출 #391162

#제출 시각아이디문제언어결과실행 시간메모리
391162keta_tsimakuridzeFurniture (JOI20_furniture)C++14
100 / 100
2301 ms36732 KiB
#include<bits/stdc++.h> #define f first #define int long long #define s second using namespace std; const int N=1005,mod=1e9+7; int t,d2[N][N],d1[N][N],p[N][N],n,m,cnt[2*N]; queue<pair<int,int> > q; char c[N][N]; bool ok(int x,int y){ if(min(x,y)<1 || x>n || y>m) return 0; return 1; } void dfs1(int x,int y){ if(d1[x][y] || c[x][y]=='1') return; d1[x][y]=1; if(ok(x+1,y)) dfs1(x+1,y); if(ok(x,y+1)) dfs1(x,y+1); } void dfs2(int x,int y){ if(d2[x][y] || c[x][y]=='1') return; d2[x][y]=1; if(ok(x-1,y)) dfs2(x-1,y); if(ok(x,y-1)) dfs2(x,y-1); } void update1(int x,int y){ if(ok(x+1,y) && p[x+1][y] && !p[x+1][y-1]) q.push({x+1,y}); if(ok(x,y+1) && p[x][y+1] && !p[x-1][y+1]) q.push({x,y+1}); while(q.size()){ x=q.front().f; y=q.front().s; q.pop(); if(p[x][y-1] || p[x-1][y]) continue; p[x][y]=0; cnt[x+y]--; if(ok(x+1,y) && p[x+1][y] && !p[x+1][y-1]) q.push({x+1,y}); if(ok(x,y+1) && p[x][y+1] && !p[x-1][y+1]) q.push({x,y+1}); } } void update2(int x,int y){ if(ok(x-1,y) && p[x-1][y] && !p[x-1][y+1]) q.push({x-1,y}); if(ok(x,y-1) && p[x][y-1] && !p[x+1][y-1]) q.push({x,y-1}); while(q.size()){ x=q.front().f; y=q.front().s; q.pop(); if(p[x][y+1] || p[x+1][y]) continue; p[x][y]=0; cnt[x+y]--; if(ok(x-1,y) && p[x-1][y] && !p[x-1][y+1]) q.push({x-1,y}); if(ok(x,y-1) && p[x][y-1] && !p[x+1][y-1]) q.push({x,y-1}); } } main(){ // t=1; cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>c[i][j]; } } dfs1(1,1); dfs2(n,m); d1[1][1]=d2[n][m]=1; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(d1[i][j] && d2[i][j]) p[i][j]=1,cnt[i+j]++; } } int q; cin>>q; while(q--){ int a,b; cin>>a>>b; if(!p[a][b] ) { cout<<1<<endl; } else { if(cnt[a+b]-1){ p[a][b]=0; cnt[a+b]--; update1(a,b); update2(a,b); cout<<1<<endl; } else cout<<0<<endl; } } }

컴파일 시 표준 에러 (stderr) 메시지

furniture.cpp:52:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 |  main(){
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...