QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#595164 | #6644. Red Black Grid | UESTC_DECAYALI# | WA | 12ms | 3728kb | C++20 | 3.7kb | 2024-09-28 12:47:32 | 2024-09-28 12:47:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 1005;
int tbl[N][N];
void solve() {
int n, k; cin >> n >> k;
if (1==k || 2*n*(n-1) - 1 == k) {
cout << "Impossible\n";
return;
}
if (1==n) {
if (k==0)
{
cout << "Possible\n";
cout << "R\n";
} else cout << "Impossible\n";
} else if (2==n) {
if (k==0)
{
cout << "Possible\n";
cout << "RR\nRR\n";
} else
if (k==2)
{
cout << "Possible\n";
cout << "BR\nRR\n";
} else
if (k==4)
{
cout << "Possible\n";
cout << "BR\nRB\n";
} else cout << "Impossible\n";
} else if (3==n) {
if (k==2)
{
cout << "Possible\n";
cout << "BRR\nRRR\nRRR\n";
} else
if (k==3)
{
cout << "Possible\n";
cout << "RBR\nRRR\nRRR\n";
} else
if (k==4)
{
cout << "Possible\n";
cout << "RRR\nRBR\nRRR\n";
} else
if (k==5)
{
cout << "Possible\n";
cout << "RRB\nRRR\nRBR\n";
} else
if (k==6)
{
cout << "Possible\n";
cout << "RBR\nRRR\nRBR\n";
} else
if (k==7)
{
cout << "Possible\n";
cout << "RBR\nRRR\nBRB\n";
} else
if (k==8)
{
cout << "Possible\n";
cout << "BRB\nRRR\nBRB\n";
} else
if (k==9)
{
cout << "Possible\n";
cout << "RBR\nRRB\nRBR\n";
} else
if (k==10)
{
cout << "Possible\n";
cout << "BRB\nRBR\nRRB\n";
} else
if (k==12)
{
cout << "Possible\n";
cout << "BRB\nRBR\nBRB\n";
} else cout << "Impossible\n";
} else {
vector<pii> pos2, pos3, pos4;
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) if ((i+j)%2==0) {
if (i!=1 && i!=n && j!=1 && j!=n) pos4.push_back({i, j});
else {
if ((i==1 || i==n) && (j==1 || j==n)) pos2.push_back({i, j});
else pos3.push_back({i, j});
}
}
int sz2=pos2.size();
int sz3=pos3.size();
int sz4=pos4.size();
vector<pii> ans;
if (k/4 <= sz4) {
for (int i=0; i<k/4; ++i) ans.push_back(pos4[i]);
if (k%4 == 1) ans.pop_back(), ans.push_back(pos2[0]), ans.push_back(pos3[0]);
else if (k%4 == 2) ans.push_back(pos2[0]);
else if (k%4 == 3) ans.push_back(pos3[0]);
} else {
ans = pos4;
if (4*sz4+1 == k) ans.push_back({1, 2});
else {
k -= 4*sz4;
int bd = (n%2==0 ? 2 : 4);
for (int i=0; i<=bd; ++i) {
if ((k-2*i)%3==0 && (k-2*i)/3 <= sz3) {
for (int j=0; j<i; ++j) ans.push_back(pos2[j]);
for (int j=0; j<(k-2*i)/3; ++j) ans.push_back(pos3[j]);
break;
}
}
}
}
cout << "Possible\n";
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) tbl[i][j] = 0;
for (auto [r, c] : ans) tbl[r][c] = 1;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=n; ++j) cout << (tbl[i][j] == 0 ? 'B' : 'R');
cout << '\n';
}
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t; while (t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
2 3 6 3 1
output:
Possible RBR RRR RBR Impossible
result:
ok correct! (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 3728kb
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 R Possible BR RB Impossible Possible BR RR Impossible Possible RR RR Possible BRB RBR BRB Impossible Possible BRB RBR RRB Possible RBR RRB RBR Possible BRB RRR BRB Possible RBR RRR BRB Possible RBR RRR RBR Possible RRB RRR RBR Possible RRR RBR RRR Possible RBR RRR RRR Possible BRR RRR RRR I...
result:
wrong answer Condition failed: "A == B" (test case 19)