QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127878#6644. Red Black Grid45645AWA 22ms3604kbC++141.6kb2023-07-20 10:54:042023-07-20 10:54:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 10:54:06]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:3604kb
  • [2023-07-20 10:54:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=1010;
inline int read()
{
	char ch;
	while((ch=getchar())<'0'||ch>'9');
	int res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0';
	return res;
}
int n,K,a[N][N];
bool dfs(int x,int y,int now)
{
	if(now>K) return 0;
	if(x==n)
	{
		if(now==K)
		{
			for(int i=0;i<n;printf("\n"),i++)
				for(int j=0;j<n;j++)
				printf("%c",a[i][j]?'R':'B');
			return 1;
		}
		return 0;
	}
	a[x][y]=0;
	int tmp=now+(x&&a[x-1][y]!=a[x][y])+(y&&a[x][y-1]!=a[x][y]);
	if(y==n-1?dfs(x+1,0,tmp):dfs(x,y+1,tmp)) return 1;
	a[x][y]=1;
	tmp=now+(x&&a[x-1][y]!=a[x][y])+(y&&a[x][y-1]!=a[x][y]);
	if(y==n-1?dfs(x+1,0,tmp):dfs(x,y+1,tmp)) return 1;
	return 0;
}
int val(int x,int y){
	return 4-(x==0||x==n-1)-(y==0||y==n-1); 
}
int cnt[5],ans[5];
bool dfs2(int now,int rst)
{
	if(now==2)
	{
		if(!(rst&1)&&2*cnt[2]>=rst) 
		{
			ans[2]=rst/2;
			return 1;
		}
		return 0;
	}
	for(int i=rst/now;i>=0;i--)
		if(dfs2(now-1,rst-i*now)) 
		{
			ans[now]=i;
			return 1;
		}
	return 0;
}
int main()
{
	int T=read();
	while(T--)
	{
		n=read(),K=read();
		if(K==1||K==2*(n-1)*n-1) printf("Impossible\n");
		else
		{
			printf("Possible\n");
			if(n<=3) dfs(0,0,0);
			else
			{
				cnt[2]=cnt[3]=cnt[4]=0;
				for(int i=0;i<n;i++)
					for(int j=0;j<n;j++)
					{
						a[i][j]=0;
						if(!((i+j)&1)) cnt[val(i,j)]++;
					}		
				dfs2(4,K);
				for(int i=0;i<n;printf("\n"),i++)
					for(int j=0;j<n;j++)
					if(!((i+j)&1)&&ans[val(i,j)]) ans[val(i,j)]--,printf("R");
					else printf("B");
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

input:

2
3 6
3 1

output:

Possible
BBB
BBR
BRB
Impossible

result:

ok correct! (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 22ms
memory: 3544kb

input:

4424
1 0
2 4
2 3
2 2
2 1
2 0
3 12
3 11
3 10
3 9
3 8
3 7
3 6
3 5
3 4
3 3
3 2
3 1
3 0
4 24
4 23
4 22
4 21
4 20
4 19
4 18
4 17
4 16
4 15
4 14
4 13
4 12
4 11
4 10
4 9
4 8
4 7
4 6
4 5
4 4
4 3
4 2
4 1
4 0
5 40
5 39
5 38
5 37
5 36
5 35
5 34
5 33
5 32
5 31
5 30
5 29
5 28
5 27
5 26
5 25
5 24
5 23
5 22
5 21
5...

output:

Possible
B
Possible
BR
RB
Impossible
Possible
BB
BR
Impossible
Possible
BB
BB
Possible
BRB
RBR
BRB
Impossible
Possible
BBR
BRB
RBR
Possible
BBB
RBR
BRB
Possible
BBB
BRB
RBR
Possible
BBB
BRR
RBB
Possible
BBB
BBR
BRB
Possible
BBB
BBR
RBB
Possible
BBB
BBB
RBR
Possible
BBB
BBB
BRB
Possible
BBB
BBB
BBR
I...

result:

wrong answer Condition failed: "getNum(vec) == k" (test case 20)