QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127396#6644. Red Black Gridyy_zq#WA 52ms3472kbC++144.2kb2023-07-19 16:54:322023-07-19 16:54:35

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-19 16:54:35]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3472kb
  • [2023-07-19 16:54:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;++i) 
char a[1011][1011];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		if(k>2*n*(n-1)){
			cout<<"Impossible"<<endl;
			continue;
		}
		if(n==1){
			cout<<"Possible"<<endl;
			cout<<"R"<<endl;
		}
		if(n==2){
			if(k==0){
				cout<<"Possible"<<endl;
				cout<<"RR"<<endl;
				cout<<"RR"<<endl;
			}
			if(k==1){
				cout<<"Impossible"<<endl;
				continue;
			}
			if(k==2){
				cout<<"Possible"<<endl;
				cout<<"RB"<<endl;
				cout<<"RR"<<endl;
			}
			if(k==3){
				cout<<"Impossible"<<endl;
				continue;
			}
			if(k==4){
				cout<<"Possible"<<endl;
				cout<<"RB"<<endl;
				cout<<"BR"<<endl;
			}
		}
		if(n==3){
			if(k==0){
				cout<<"Possible"<<endl;
				cout<<"RRR"<<endl;
				cout<<"RRR"<<endl;
				cout<<"RRR"<<endl;
			}
			if(k==1){
				cout<<"Impossible"<<endl;
				continue;
			}
			if(k==2){
				cout<<"Possible"<<endl;
				cout<<"BRR"<<endl;
				cout<<"RRR"<<endl;
				cout<<"RRR"<<endl;
			}
			if(k==3){
				cout<<"Possible"<<endl;
				cout<<"RBR"<<endl;
				cout<<"RRR"<<endl;
				cout<<"RRR"<<endl;
			}
			if(k==4){
				cout<<"Possible"<<endl;
				cout<<"RRR"<<endl;
				cout<<"RBR"<<endl;
				cout<<"RRR"<<endl;
			}
			if(k==5){
				cout<<"Possible"<<endl;
				cout<<"BRR"<<endl;
				cout<<"RRB"<<endl;
				cout<<"RRR"<<endl;
			}
			if(k==6){
				cout<<"Possible"<<endl;
				cout<<"RBR"<<endl;
				cout<<"RRB"<<endl;
				cout<<"RRR"<<endl;
			}
			if(k==7){
				cout<<"Possible"<<endl;
				cout<<"BRR"<<endl;
				cout<<"RRB"<<endl;
				cout<<"BRR"<<endl;
			}
			if(k==8){
				cout<<"Possible"<<endl;
				cout<<"BRB"<<endl;
				cout<<"RRR"<<endl;
				cout<<"BRB"<<endl;
			}
			if(k==9){
				cout<<"Possible"<<endl;
				cout<<"RBR"<<endl;
				cout<<"BRB"<<endl;
				cout<<"RRR"<<endl;
			}
			if(k==10){
				cout<<"Possible"<<endl;
				cout<<"RBR"<<endl;
				cout<<"BRB"<<endl;
				cout<<"RBB"<<endl;
			}
			if(k==11){
				cout<<"Impossible"<<endl;
				continue;
			}
			if(k==12){
				cout<<"Possible"<<endl;
				cout<<"RBR"<<endl;
				cout<<"BRB"<<endl;
				cout<<"RBR"<<endl;
			}
			continue;
		}
		if(n>=4){
//			if(k>=n*(n-1)){
//				k = (2*n*(n-1)) - k;
//				FOR(i,1,n){
//					FOR(j,1,n){//相加奇数是红色 
//						if((i+j)&1) a[i][j]='R';
//						else a[i][j]='B';
//					}
//				}
//				if(k==1){
//					cout<<"Impossible"<<endl;
//					continue;
//				}
//				else{
//					cout<<"Possible"<<endl;
//					//此处我们把黑色改成红色
//					int cnt = k;
//					FOR(i,2,n){
//						FOR(j,1,n){
//							if(a[i][j]=='B'&&cnt >=3){
//								a[i][j]='R';
//								if(i==n||i==1||j==n||j==1) cnt-=3;
//								else cnt-=4;
//							}
//						}
//					}
//					if(cnt==1){
//						a[2][2]='B';
//						a[1][1]='R';
//						a[1][3]='R';
//					}
//					if(cnt==2){
//						a[1][1]='R';
//					}
//					if(cnt==3){
//						a[1][3]='R';
//					}
//					FOR(i,1,n){
//						FOR(j,1,n){
//							cout<<a[i][j];
//						}
//						cout<<endl;
//					}
//				}
//			}
//			else{
				FOR(i,1,n){
					FOR(j,1,n){//默认是黑色 
						a[i][j]='B';
					}
				}
				if(k==1||k==(2*n*(n-1))-1){
					cout<<"Impossible"<<endl;
					continue;
				}
				else{
					cout<<"Possible"<<endl;
					//此处我们把黑色改成红色
					int cnt = k;
					if(cnt>=4) cnt-=4,a[2][2]='R';
					FOR(i,1,n){
						FOR(j,1,n){
							if(i==1&&j==1) j=4;
							if(!((i+j)&1) && cnt &&a[i][j]=='B'){
								int tmp = 4;
								if(i==n||i==1) --tmp;
								if(j==n||j==1) --tmp;
								if(cnt>=tmp){
									a[i][j]='R';
									cnt-=tmp;
								}
							}
						}
					}
					if(cnt==1){
						a[2][2]='B';
						a[1][1]='R';
						a[1][3]='R';
					}
					if(cnt==2){
						a[1][1]='R';
					}
					if(cnt==3){
						a[1][3]='R';
					}
					if(cnt==5){
						a[1][1]='R';
						a[1][3]='R';
					}
					FOR(i,1,n){
						FOR(j,1,n){
							cout<<a[i][j];
						}
						cout<<endl;
					}
				}
//			}
		}
	}
	return 0;
}
/*
10
5 
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 6
3 1

output:

Possible
RBR
RRB
RRR
Impossible

result:

ok correct! (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 52ms
memory: 3472kb

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
R
Possible
RB
BR
Impossible
Possible
RB
RR
Impossible
Possible
RR
RR
Possible
RBR
BRB
RBR
Impossible
Possible
RBR
BRB
RBB
Possible
RBR
BRB
RRR
Possible
BRB
RRR
BRB
Possible
BRR
RRB
BRR
Possible
RBR
RRB
RRR
Possible
BRR
RRB
RRR
Possible
RRR
RBR
RRR
Possible
RBR
RRR
RRR
Possible
BRR
RRR
RRR
I...

result:

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