Submission #425005

# Submission time Handle Problem Language Result Execution time Memory
425005 2021-06-12T12:23:22 Z p_square Furniture (JOI20_furniture) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>

bool avail[15][15][4];
bool C[15][15];
int maxn = 15;

void block(int x, int y)
{
	//cout<<"Blocking "<<x<<" "<<y<<endl;
	if(C[x][y] == 1)
		return;
	C[x][y] = 1;

	avail[x][y+1][0] = 0;
	avail[x][y-1][2] = 0;
	avail[x+1][y][1] = 0;
	avail[x-1][y][3] = 0;

	if(avail[x][y][2])
	{
		if(!avail[x][y+1][1])
			block(x, y+1);
	}
	if(avail[x][y][3])
	{
		if(!avail[x+1][y][0])
			block(x+1, y);
	}
	if(avail[x][y][0])
	{
		if(!avail[x][y-1][3])
			block(x,y-1);
	}
	if(avail[x][y][1])
	{
		if(!avail[x-1][y][2])
			block(x-1, y);
	}
}

int main()
{
	int n, m, q;
	cin>>n>>m;
	for(int i = 0; i<maxn; i++)
	{
		for(int j = 0; j<maxn; j++)
		{
			for(int dir = 0; dir<4; dir++)
			{
				avail[i][j][dir] = 0;
			}
			C[i][j] = 1;
		}
	}

	for(int i = 1; i<=n; i++)
	{
		for(int j = 1; j<=m; j++)
		{
			if(i!=1)
				avail[i][j][1]=1;
			if(i!=n)
				avail[i][j][3]=1;
			if(j!=1)
				avail[i][j][0]=1;
			if(j!=m)
				avail[i][j][2]=1;

			C[i][j] = 0;
		}
	}

	int t;
	for(int i = 1; i<=n; i++)
	{
		for(int j = 1; j<=m; j++)
		{
			cin>>t;
			if(t)
				block(i,j);
		}
	}

	/*
	for(int i = 0; i<10; i++)
	{
		for(int j = 0; j<10; j++)
		{
			cout<<C[i][j]<<" ";
		}
		cout<<endl;
	}
	*/

	cin>>q;
	int x, y, js, ct;
	while(q--)
	{
		cin>>x>>y;
		if(C[x][y] == 1)
		{
			cout<<1<<endl;
			continue;
		}
		ct = 0;
		for(int i = 1; i<=n; i++)
		{
			js = x+y-i;
			if(js < 1 || js > m)
				continue;

			if(C[i][js]==0)
				ct++;
		}

		if(ct>1)
		{
			cout<<1<<endl;
			block(x,y);
		}
		else
		{
			cout<<0<<endl;
		}
	}

}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -