제출 #296138

#제출 시각아이디문제언어결과실행 시간메모리
296138PyqeFurniture (JOI20_furniture)C++14
100 / 100
459 ms3320 KiB
#include <bits/stdc++.h>

using namespace std;

long long n,m,fq[2069],vy[4]={-1,0,1,0},vx[4]={0,1,0,-1};
bitset<1069> a[1069];

void dfs(long long y,long long x)
{
	long long im,yy,xx;
	
	a[y][x]=1;
	fq[y+x]--;
	for(im=0;im<4;im++)
	{
		yy=y+vy[im];
		xx=x+vx[im];
		if(!(yy==1&&xx==1)&&!(yy==n&&xx==m)&&!a[yy][xx]&&((a[yy-1][xx]&&a[yy][xx-1])||(a[yy+1][xx]&&a[yy][xx+1])))
		{
			dfs(yy,xx);
		}
	}
}

int main()
{
	long long t,rr,i,j,k,l,z;
	
	scanf("%lld%lld",&n,&m);
	for(i=0;i<=n+1;i++)
	{
		for(j=0;j<=m+1;j++)
		{
			a[i][j]=!i||i==n+1||!j||j==m+1;
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			scanf("%lld",&k);
			if(k&&!a[i][j])
			{
				dfs(i,j);
			}
			fq[i+j]++;
		}
	}
	scanf("%lld",&t);
	for(rr=0;rr<t;rr++)
	{
		scanf("%lld%lld",&k,&l);
		if(a[k][l]||fq[k+l]-1)
		{
			if(!a[k][l])
			{
				dfs(k,l);
			}
			z=1;
		}
		else
		{
			z=0;
		}
		printf("%lld\n",z);
	}
}

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

furniture.cpp: In function 'int main()':
furniture.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%lld%lld",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
furniture.cpp:41:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |    scanf("%lld",&k);
      |    ~~~~~^~~~~~~~~~~
furniture.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |  scanf("%lld",&t);
      |  ~~~~~^~~~~~~~~~~
furniture.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |   scanf("%lld%lld",&k,&l);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...