QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135188 | #6644. Red Black Grid | ckz# | WA | 14ms | 3680kb | C++20 | 3.6kb | 2023-08-05 12:37:30 | 2023-08-05 12:37:33 |
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";
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;
}
}
}
// cerr << x << " " << y << " " << z << "\n";
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;
// 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 solve()
{
cin >> n >> m;
if (n % 2==1) work1();
else work2();
// work1();
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3492kb
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: 14ms
memory: 3680kb
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 BR Impossible Possible RB BR Possible RBR BRB RBR Impossible Possible RBR BRB RBR Impossible Possible RBR BRB RBR Impossible Possible RBR BRB RBR Impossible Possible RBR BRB RBR Impossible Possible RBR BRB RBR Impossible Possible RBR BRB RBR Possible ...
result:
wrong answer Condition failed: "A == B" (test case 1)