QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201190 | #6644. Red Black Grid | yumingsk | TL | 0ms | 3712kb | C++14 | 2.1kb | 2023-10-05 13:02:19 | 2023-10-05 13:02:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int a[5],b[N],i,j,n,cnt2,cnt3,cnt4;
char c[1005][1005];
void solve()
{
int n,k;
cin>>n>>k;
int maxn=n*(n-1)*2;
if(k==1||k>maxn||k==maxn-1){
cout<<"Impossible"<<'\n';
return ;
}
if(n%2==1)
{
a[2]=4;
a[3]=((n-2)/2)*4;
a[4]=n*n/2+1-a[3]-4;
}
else
{
a[2]=2;
a[3]=2*n-4;
a[4]=n*n/2-a[3]-2;
}
if(k%2==1)
{
cnt3=0,cnt2=0;
cnt4=0;
int f=0;
for(i=1;i<=a[3];i=i+2){
int nd=(k-i*3)/4;
if(nd<=a[4]){
if((k-i*3)%4==0){
cnt4=nd;
cnt3=i;
}
else{
cnt4=nd;
cnt3=i;
cnt2=1;
}
f=1;
break;
}
if(nd>a[4]&&nd<=a[4]+a[2]/2){
cnt2=(k-3*i-4*a[4])/2;
f=1;
cnt4=a[4];
cnt3=i;
break;
}
}
}
else{
cnt3=0,cnt2=0;
cnt4=0;
int f=0;
for(i=0;i<=a[3];i+=2){
int nd=(k-i*3)/4;
if(nd<=a[4]){
if((k-i*3)%4==0){
cnt4=nd;
cnt3=i;
}
else{
cnt4=nd;
cnt3=i;
cnt2=1;
}
f=1;
break;
}
if(nd>a[4]&&nd<=a[4]+2){
cnt2=(k-3*i-4*a[4])/2;
f=1;
cnt4=a[4];
cnt3=i;
break;
}
}
}
cout<<"Possible"<<'\n';
//cout<<a[2]<<" "<<a[3]<<" "<<a[4]<<"\n";
//cout<<cnt2<<" "<<cnt3<<" "<<cnt4<<" \n";
for(int i =1;i<=n;i++)
{
for(int j =1;j<=n;j++)
{
c[i][j]='R';
}
}
if(n%2==1)
{
for(i=1;i<=n;i=i+n-1){
for(j=1;j<=n;j=j+n-1){
if(cnt2){
cnt2--;
c[i][j]='B';
}
else{
c[i][j]='R';
}
}
}
}
else
{
if(cnt2==1)
{
c[1][n]='B';
}
else if (cnt2==2)
{
c[1][n]='B';
c[n][1]='B';
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i==1||j==1||i==n||j==n){
if(i==1&&j==1)continue;
if(i==1&&j==n)continue;
if(i==n&&j==n)continue;
if(i==n&&j==1)continue;
if((i+j)%2==0&&cnt3){
c[i][j]='B';
cnt3--;
}
}
else{
if((i+j)%2==0&&cnt4){
c[i][j]='B';
cnt4--;
}
}
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
cout<<c[i][j];
}
cout<<'\n';
}
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
2 3 6 3 1
output:
Possible BRR RBR RRR Impossible
result:
ok correct! (2 test cases)
Test #2:
score: -100
Time Limit Exceeded
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...