QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135247 | #6644. Red Black Grid | ckz# | WA | 19ms | 3588kb | C++20 | 4.3kb | 2023-08-05 13:13:01 | 2023-08-05 13:13:05 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()
using namespace std;
const int maxn = 1e3 + 10;
ll n,m;
ll cnt2,cnt3,cnt4;
ll col[maxn][maxn];
void work1()
{
cnt2=4;
cnt3=(n/2-1)*2+(n-2)/2*2;
cnt4=(n-2)*(n-2)/2+1;
bool flag=0;
int x,y,z;
for (int i=0; i<=cnt2; i++)
{
for (int j=0; j<=cnt3; j++)
{
int k=(m-i*2-j*3)/4;
if (k>=0 && k<=cnt4 && i*2+j*3+k*4==m) {
x=i; y=j; z=k;
flag=1;
break;
}
}
}
if (flag==0) {
cout << "Impossible\n";
return;
}
cout << "Possible\n";
if (x==1) {
col[1][1]=1;
} else if (x==2) {
col[1][1]=1;
col[1][n]=1;
} else if (x==3) {
col[1][1]=1;
col[1][n]=1;
col[n][1]=1;
} else if (x==4) {
col[1][1]=1;
col[1][n]=1;
col[n][1]=1;
col[n][n]=1;
}
ll q,p;
q=3;
while (y) {
if (q>=n) break;
col[1][q]=1;
y--;
q+=2;
}
q=3;
while (y) {
if (q>=n) break;
col[n][q]=1;
y--;
q+=2;
}
q=3;
while (y) {
if (q>=n) break;
col[q][1]=1;
y--;
q+=2;
}
q=3;
while (y) {
if (q>=n) break;
col[q][n]=1;
y--;
q+=2;
}
p=2,q=2;
// cerr << z << "\n";
while (z)
{
col[p][q]=1;
q+=2;
if (q>=n) {
p++;
q=p%2+2;
}
z--;
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n; j++)
if (col[i][j]) cout << "R";
else cout << "B";
cout << "\n";
}
}
void work2()
{
cnt2=2;
cnt3=n-2+n-2;
cnt4=(n-2)*(n-2)/2;
// cerr << cnt2<<" " << cnt3 << " " << cnt4 << "\n";
// cerr <<
bool flag=0;
int x,y,z;
for (int i=0; i<=cnt2; i++)
{
for (int j=0; j<=cnt3; j++)
{
int k=(m-i*2-j*3)/4;
if (k>=0 && k<=cnt4 && i*2+j*3+k*4==m) {
x=i; y=j; z=k;
flag=1;
break;
}
}
}
if (flag==0) {
cout << "Impossible\n";
return;
}
cout << "Possible\n";
if (x==1) {
col[1][1]=1;
} else if (x==2) {
col[1][1]=1;
col[n][n]=1;
}
ll q,p;
q=3;
while (y) {
if (q>=n) break;
col[1][q]=1;
y--;
q+=2;
}
q=2;
while (y) {
if (q>=n) break;
col[n][q]=1;
y--;
q+=2;
}
q=3;
while (y) {
if (q>=n) break;
col[q][1]=1;
y--;
q+=2;
}
q=2;
while (y) {
if (q>=n) break;
col[q][n]=1;
y--;
q+=2;
}
p=2,q=2;
while (z)
{
col[p][q]=1;
q+=2;
if (q>=n) {
p++;
q=p%2+2;
}
z--;
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n; j++)
if (col[i][j]) cout << "R";
else cout << "B";
cout << "\n";
}
}
void solve()
{
cin >> n >> m;
if (n==3 && m==3)
{
cout << "Possible\n";
cout << "BRB\n";
cout << "BBB\n";
cout << "BBB\n";
return;
}
if (n==3 && m==5)
{
cout << "Possible\n";
cout << "BRB\n";
cout << "BBB\n";
cout << "RBB\n";
return;
}
if (n==3 && m==7)
{
cout << "Possible\n";
cout << "BRB\n";
cout << "BBB\n";
cout << "RBR\n";
return;
}
if (n==3 && m==9)
{
cout << "Possible\n";
cout << "BBB\n";
cout << "RBR\n";
cout << "BRB\n";
return;
}
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n; j++)
col[i][j]=0;
}
if (n % 2==1) work1();
else work2();
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t = 1;
cin >> t;
while(t--) solve();
// for (int i=1; i<=n; i++)
// {
// for (int j=1; j<=2*n*n-1))
// }
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
2 3 6 3 1
output:
Possible RBR BBB RBB Impossible
result:
ok correct! (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 19ms
memory: 3588kb
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:
Impossible Possible RB BR Impossible Possible RB BB Impossible Possible BB BB Possible RBR BRB RBR Impossible Possible RBR BRB RBB Possible BBB RBR BRB Possible RBR BBB RBR Possible BRB BBB RBR Possible RBR BBB RBB Possible BRB BBB RBB Possible RBR BBB BBB Possible BRB BBB BBB Possible RBB BBB BBB I...
result:
wrong answer Condition failed: "A == B" (test case 1)