# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1093333 | 2024-09-26T15:09:26 Z | 8pete8 | Furniture (JOI20_furniture) | C++17 | 2 ms | 11008 KB |
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<cassert> #include<unordered_map> #include <queue> #include <cstdint> #include<cstring> #include<limits.h> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> #include<bitset> using namespace std; #define ll long long #define f first #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-lopps") #define int long long using namespace std; const int mod=998244353,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30; //#undef int int n,k,m,q; void setIO(string name){ ios_base::sync_with_stdio(0); cin.tie(0); freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } int grid[2002][2002],can[2002][2002],can2[2002][2002],yes[2002][2002]; int cnt[2002]; //0=l, 1=r void update(int x,int y){ if(x<=0||y<=0)return; if(!yes[x][y])return; if(grid[x][y]==0&&(yes[x+1][y]||yes[x][y+1]))return; yes[x][y]=0; cnt[x+y]--; update(x-1,y); update(x,y-1); } void update2(int x,int y){ if(x>n||y>m)return; if(!yes[x][y])return; if(grid[x][y]==0&&(yes[x-1][y]||yes[x][y-1]))return; yes[x][y]=0; cnt[x+y]--; update(x+1,y); update(x,y+1); } int32_t main(){ fastio cin>>n>>m; for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>grid[i][j]; for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){ if(i==1&&j==1)can[i][j]=1; if(grid[i][j])continue; can[i][j]|=(can[i-1][j]|can[i][j-1]); } for(int i=n;i>=1;i--)for(int j=m;j>=1;j--){ if(i==n&&j==m)can2[i][j]=1; if(grid[i][j])continue; can2[i][j]|=(can2[i+1][j]|can2[i][j+1]); } for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){ yes[i][j]=(can[i][j]&can2[i][j]); if(yes[i][j])cnt[i+j]++; } int q;cin>>q; while(q--){ int x,y;cin>>x>>y; if(!yes[x][y])cout<<1<<'\n'; else{ if(cnt[x+y]>1){ cout<<1<<'\n'; grid[x][y]=1; cnt[x+y]++; update(x,y); yes[x][y]=1; update2(x,y); } else cout<<0<<'\n'; } } } /* */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 10584 KB | Output is correct |
2 | Incorrect | 2 ms | 11008 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 10584 KB | Output is correct |
2 | Incorrect | 2 ms | 11008 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |