# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
421068 | inwbear | Furniture (JOI20_furniture) | C++14 | 0 ms | 204 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int n,m,q,xi,xj,co[1005][1005][2],k,fur[1005][1005],mi;
bool cc;
queue<pair<int,int> >qq;
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&fur[i][j]);
}
}
co[1][1][0]=1;
co[n][m][1]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(fur[i][j]==1||co[i][j][0]==0)continue;
if(fur[i+1][j]==0)co[i+1][j][0]++;
if(fur[i][j+1]==0)co[i][j+1][0]++;
}
}
for(int i=n;i>0;i--)
{
for(int j=m;j>0;j--)
{
if(fur[i][j]==1||co[i][j][1]==0)continue;
if(fur[i-1][j]==0)co[i-1][j][1]++;
if(fur[i][j-1]==0)co[i][j-1][1]++;
}
}
scanf("%d",&q);
while(q--)
{
cc=false;
scanf("%d %d",&xi,&xj);
co[1][1][0]=1;
co[n][m][1]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(fur[i][j]==1||co[i][j][0]==0)continue;
if(fur[i+1][j]==0)co[i+1][j][0]++;
if(fur[i][j+1]==0)co[i][j+1][0]++;
}
}
for(int i=n;i>0;i--)
{
for(int j=m;j>0;j--)
{
if(fur[i][j]==1||co[i][j][1]==0)continue;
if(fur[i-1][j]==0)co[i-1][j][1]++;
if(fur[i][j-1]==0)co[i][j-1][1]++;
}
}
mi=1;
for(int i=xi-1;i>0;i--)
{
if(fur[i][xj]==1)mi=0;
if(co[i][xj][0]>0&&co[i][xj][1]-mi>0)cc=true;
}
for(int j=xj-1;j>0;j--)
{
if(fur[xi][j]==1)mi=0;
if(co[xi][j][0]>0&&co[xi][j][1]-mi>0)cc=true;
}
for(int i=xi+1;i<=n;i++)
{
if(fur[i][xj]==1)mi=0;
if(co[i][xj][0]>0&&co[i][xj][1]-mi>0)cc=true;
}
for(int j=xj+1;j<=m;j++)
{
if(fur[xi][j]==1)mi=0;
if(co[xi][j][0]>0&&co[xi][j][1]-mi>0)cc=true;
}
if(cc)
{
printf("1\n");
fur[xi][xj]=1;
qq.push({xi,xj});
while(!qq.empty())
{
if(qq.front().F+1<=n)
{
co[qq.front().F+1][qq.front().S][0]--;
if(co[qq.front().F+1][qq.front().S][0]==0)
{
qq.push({qq.front().F+1,qq.front().S});
}
}
if(qq.front().S+1<=m)
{
co[qq.front().F][qq.front().S+1][0]--;
if(co[qq.front().F][qq.front().S+1][0]==0)
{
qq.push({qq.front().F,qq.front().S+1});
}
}
qq.pop();
}
qq.push({xi,xj});
while(!qq.empty())
{
if(qq.front().F-1>0)
{
co[qq.front().F-1][qq.front().S][1]--;
if(co[qq.front().F-1][qq.front().S][1]==0)
{
qq.push({qq.front().F-1,qq.front().S});
}
}
if(qq.front().S-1>0)
{
co[qq.front().F][qq.front().S-1][1]--;
if(co[qq.front().F][qq.front().S-1][1]==0)
{
qq.push({qq.front().F,qq.front().S-1});
}
}
qq.pop();
}
}
else printf("0\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |