QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135084 | #6644. Red Black Grid | BoulevardDust# | WA | 1ms | 3668kb | C++17 | 2.6kb | 2023-08-05 11:16:36 | 2023-08-05 11:16:37 |
Judging History
answer
#include<bits/stdc++.h>
#define N 1005
#define re
#define ll long long
using namespace std;
int n,m,K,q,T;
inline void Rd(int &res){
re char c;res=0;
while(c=getchar(),c<48);
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>47);
}
char c[N][N];
int main(){
Rd(T);
while(T--){
Rd(n);Rd(K);
if(n==3&&K==5){
puts("Possible");
puts("RBB");
puts("BBB");
puts("BRB");
continue;
}
if(n==3&&K==7){
puts("Possible");
puts("RBR");
puts("BBB");
puts("BRB");
continue;
}
int cnt2=0,cnt3=0,cnt4=0;
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++){
if((i+j)%2==0)c[i][j]='B';
else{
int t1=(i==1||i==n),t2=(j==1||j==n);
if(t1&&t2)cnt2++;
else if(t1||t2)cnt3++;
else cnt4++;
}
}
int need2=-1,need3=0,need4=0;
for(re int i=0;i<=cnt2;i++)
for(re int j=0;j<=cnt3;j++){
int now=K-i*2-j*3;
if(now>=0&&now%4==0&&now/4<=cnt4){
need2=i;
need3=j;
need4=now/4;
break;
}
}
if(need2!=-1){
puts("Possible");
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++){
if((i+j)%2==0)continue;
int t1=(i==1||i==n),t2=(j==1||j==n);
if(t1&&t2 && need2)need2--,c[i][j]='R';
else if((t1+t2==1) && need3)need3--,c[i][j]='R';
else if(t1+t2==0&&need4)need4--,c[i][j]='R';
else c[i][j]='B';
}
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++){
putchar(c[i][j]);
if(j==n)putchar('\n');
}
continue;
}
cnt2=0,cnt3=0,cnt4=0;
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++){
if((i+j)%2==1)c[i][j]='B';
else{
int t1=(i==1||i==n),t2=(j==1||j==n);
if(t1&&t2)cnt2++;
else if(t1||t2)cnt3++;
else cnt4++;
}
}
need2=-1,need3=0,need4=0;
for(re int i=0;i<=cnt2;i++)
for(re int j=0;j<=cnt3;j++){
int now=K-i*2-j*3;
if(now>=0&&now%4==0&&now/4<=cnt4){
need2=i;
need3=j;
need4=now/4;
break;
}
}
if(need2!=-1){
puts("Possible");
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++){
if((i+j)%2==1)continue;
int t1=(i==1||i==n),t2=(j==1||j==n);
if(t1&&t2 && need2)need2--,c[i][j]='R';
else if((t1+t2==1) && need3)need3--,c[i][j]='R';
else if(t1+t2==0&&need4)need4--,c[i][j]='R';
else c[i][j]='B';
}
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++){
putchar(c[i][j]);
if(j==n)putchar('\n');
}
continue;
}
if(need2==-1){
printf("%d %d\n", n, K);
puts("Impossible");
continue;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3668kb
input:
2 3 6 3 1
output:
Possible BRB RBB BBB 3 1 Impossible
result:
wrong answer Condition failed: "A == B" (test case 2)