QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134985 | #6644. Red Black Grid | SolitaryDream# | WA | 5ms | 3640kb | C++20 | 2.1kb | 2023-08-05 10:29:22 | 2023-08-05 10:29:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int mp[N][N];
inline void BF(int n, int k) {
for (int s = 0; s < (1 << n * n); ++s) {
for (int i = 0, w = s; i < n; ++i)
for (int j = 0; j < n; ++j) {
mp[i][j] = w & 1;
w >>= 1;
}
int cnt = 0;
for (int i = 0, w = s; i < n; ++i)
for (int j = 0; j < n; ++j) {
if (i + 1 < n) cnt += (mp[i][j] ^ mp[i + 1][j]);
if (j + 1 < n) cnt += (mp[i][j] ^ mp[i][j + 1]);
}
if (cnt == k) {
puts("Possible");
for (int i = 0; i < n; puts(""), ++i)
for (int j = 0; j < n; ++j)
putchar("RB"[mp[i][j]]);
return;
}
}
puts("Impossible");
}
inline void Solve(int n, int k) {
vector<int> st[5];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
mp[i][j] = 0;
if ((i + j) % 2 == 0) {
int p1 = (i == 0 || i == n - 1);
int p2 = (j == 0 || j == n - 1);
st[4 - p1 - p2].push_back(i << 10 | j);
}
}
for (int i = 0; 2 * i <= k && i < (int)st[2].size(); ++i)
for (int j = 0; 2 * i + 3 * j <= k && j < (int)st[3].size(); ++j) {
int t = k - 2 * i - 3 * j;
if (t % 4) continue;
if (t / 4 > st[4].size()) continue;
t /= 4;
puts("Possible");
while (i) --i, mp[st[2][i] >> 10][st[2][i] & 1023] = 1;
while (j) --j, mp[st[3][j] >> 10][st[3][j] & 1023] = 1;
while (t) --t, mp[st[4][t] >> 10][st[4][t] & 1023] = 1;
for (int i = 0; i < n; puts(""), ++i)
for (int j = 0; j < n; ++j)
putchar("RB"[mp[i][j]]);
return;
}
puts("Impossible");
}
int main() {
int Case;
scanf("%d", &Case);
while (Case--) {
int n, k;
scanf("%d%d", &n, &k);
if (n <= 3) BF(n, k);
else Solve(n, k);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
input:
2 3 6 3 1
output:
Possible RBR BRR RRR Impossible
result:
ok correct! (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3640kb
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 RB BR Impossible Possible BR RR Impossible Possible RR RR Possible RBR BRB RBR Impossible Possible BRB RBR BRR Possible RBR BRB RRR Possible BRB RBR RRR Possible RRB BBR RRR Possible RBR BRR RRR Possible RRB BRR RRR Possible BRB RRR RRR Possible RBR RRR RRR Possible BRR RRR RRR I...
result:
wrong answer Condition failed: "A == B" (test case 20)