QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202290 | #6644. Red Black Grid | arseny_y# | WA | 1ms | 3572kb | C++23 | 2.9kb | 2023-10-05 21:33:47 | 2023-10-05 21:33:47 |
Judging History
answer
//I wrote this code 4 u today
#include <bits/stdc++.h>
template<class t> using vc = std::vector<t>;
#define nd node*
#define pnd pair<nd, nd>
//using namespace std;
typedef long long ll;
template<const ll MOD>
struct mod_mul : std::multiplies<const ll> {
ll operator()(const ll a, const ll b) {
return (a * b) % MOD;
}
};
template<typename T>
inline void sort(T &a) {
sort(a.begin(), a.end());
}
template<typename T>
inline void unique(T &a) {
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template<typename T>
inline void reverse(T &a) {
reverse(a.begin(), a.end());
}
const ll INF = 9023372036854775808ll;
const ll MOD = 1000000007ll;
std::pair<int, int> q[4] = {{0, 1},
{1, 0},
{0, -1},
{-1, 0}};
int a[3005][3005];
int max = 0;
int n, k;
bool gen(int i, int j) {
if (j == n) ++i, j = 0;
if (i == n) {
return false;
}
if (max < k) return false;
if (max == k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) std::cout << (a[i][j] ? 'B' : 'R');
std::cout << '\n';
}
return true;
}
int hru1 = 0;
for (auto [d1, d2]: q) {
int i1 = i + d1, j1 = j + d2;
if (i1 != -1 && j1 != -1 && i1 != n && j1 != n) hru1 += a[i][j] != a[i1][j1];
}
a[i][j] ^= 1;
int hru2 = 0;
for (auto [d1, d2]: q) {
int i1 = i + d1, j1 = j + d2;
if (i1 != -1 && j1 != -1 && i1 != n && j1 != n) hru2 += a[i][j] != a[i1][j1];
}
a[i][j] ^= 1;
if (hru2 < hru1) {
max += hru2 - hru1;
a[i][j] ^= 1;
if (gen(i, j + 1)) return true;
a[i][j] ^= 1;
max -= hru2 - hru1;
if (gen(i, j + 1)) return true;
} else {
if (gen(i, j + 1)) return true;
a[i][j] ^= 1;
max += hru2 - hru1;
if (gen(i, j + 1)) return true;
a[i][j] ^= 1;
max -= hru2 - hru1;
}
return false;
}
int main() {
std::cin.tie(nullptr)->ios_base::sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
max = 0;
std::cin >> n >> k;
int hex = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
a[i][j] = 0;
if (max < k && (i + j) % 2) {
a[i][j] = 1;
}
hex += i != n - 1;
hex += j != n - 1;
max += (j + 1 != n && a[i][j] != a[i][j + 1]) + (i + 1 != n && a[i][j] != a[i + 1][j]);
}
}
// std::cout << max << '\n';
if (k > hex || k == hex - 1 || k == 1) {
std::cout << "Impossible\n";
// gen(0, 0);
} else {
std::cout << "Possible\n";
gen(0, 0);
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3572kb
input:
2 3 6 3 1
output:
Possible RBR BRB RBR Impossible
result:
wrong answer Condition failed: "getNum(vec) == k" (test case 1)