QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463047 | #6644. Red Black Grid | grass8cow# | WA | 31ms | 5816kb | C++17 | 1.6kb | 2024-07-04 12:12:28 | 2024-07-04 12:12:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
int xo(int s,int x,int y){
return ((s>>x)&1)!=((s>>y)&1);
}
int s[1010][1010],t[5];
int a[2010000][5];
void sol(){
scanf("%d%d",&n,&m);
if(n<=3){
for(int s=0;s<(1<<(n*n));s++){
int su=0;
for(int i=0;i<n;i++)for(int j=0;j<n;j++){
if(i)su+=xo(s,i*n+j,(i-1)*n+j);
if(j)su+=xo(s,i*n+j,i*n+(j-1));
}
if(su==m){
puts("Possible");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)printf("%c",((s>>(i*n+j))&1)?'R':'B');
puts("");
}
return;
}
}
puts("Impossible");return;
}
int xo=2*n*(n-1);
if(m==1||m==xo-1){puts("Impossible");return;}
memset(t,0,sizeof(t));
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(!((i+j)&1))
s[i][j]=(i>1)+(i<n)+(j>1)+(j<n),t[s[i][j]]++;
for(int i=0;i<=xo;i++)for(int j=0;j<5;j++)a[i][j]=-1;
for(int j=0;j<5;j++)a[0][j]=0;
for(int o=2;o<=4;o++){
for(int i=0;i<=xo;i++){
if(a[i][0]!=-1)continue;
if(i>=o&&a[i-o][0]!=-1&&a[i-o][o]<t[o]){for(int j=0;j<5;j++)a[i][j]=a[i-o][j]+(j==o);}
}
}
m=xo-m;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
if((i+j)&1)printf("R");
else{
int o=s[i][j];
if(a[m][o])
a[m][o]--,printf("R");
else printf("B");
}
if(j==n)puts("");
}
}
int main(){
int T;scanf("%d",&T);
while(T--)sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
input:
2 3 6 3 1
output:
Possible BRB RBB BBB Impossible
result:
ok correct! (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 31ms
memory: 5816kb
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 RB BB Impossible Possible BB BB Possible BRB RBR BRB Impossible Possible RBR BRB RBB Possible BRB RBR BBB Possible RBR BRB BBB Possible BBR RRB BBB Possible BRB RBB BBB Possible BBR RBB BBB Possible RBR BBB BBB Possible BRB BBB BBB Possible RBB BBB BBB I...
result:
wrong answer Condition failed: "A == B" (test case 20)