Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC target("avx2")
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(x) cerr<<" smotri huinyi : "<<#x<<' '<<x<<'\n';
- #include "bits/stdc++.h"
- //#include "geometry.h"
- //#include "data_structure.h"
- using namespace std;
- using namespace chrono;
- #define all(a) a.begin(), a.end()
- #define allr(a) a.rbegin(), a.rend()
- #define sqrt(x) sqrtl(x)
- mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
- typedef int ll;
- typedef long double ld;
- vector<vector<bool>> used;
- ll n, m;
- struct Info {
- ll i, j;
- Info(ll _i, ll _j) : i(_i), j(_j) {}
- Info() : i(-1), j(-1) {}
- };
- ll cnt_of_rank(Info& h) {
- ll i = h.i;
- ll j = h.j;
- ll ans = 0;
- if (j + 1 < 4 * m) {
- ans += (used[i][j + 1] == false);
- }
- if (j - 1 >= 0) {
- ans += (used[i][j - 1] == false);
- }
- if (i + 1 < 4 * n) {
- ans += (used[i + 1][j] == false);
- }
- if (i - 1 >= 0) {
- ans += (used[i - 1][j] == false);
- }
- return ans;
- }
- void push(vector <Info>& sub, ll i, ll j, ll n, ll m, vector<vector<bool>>& used) {
- if (j + 1 < 4 * m) {
- if (!used[i][j + 1]) {
- sub.push_back(Info(i, j + 1));
- }
- }
- if (j - 1 >= 0) {
- if (!used[i][j - 1]) {
- sub.push_back(Info(i, j - 1));
- }
- }
- if (i + 1 < 4 * n) {
- if (!used[i + 1][j]) {
- sub.push_back(Info(i + 1, j));
- }
- }
- if (i - 1 >= 0) {
- if (!used[i - 1][j]) {
- sub.push_back(Info(i - 1, j));
- }
- }
- }
- void clean(vector <Info>& fix) {
- if (fix.empty()) {
- return;
- }
- auto it = fix.end();
- it--;
- Info sub = *it;
- if (used[sub.i][sub.j]) {
- fix.pop_back();
- }
- while (!fix.empty()) {
- it = fix.end();
- it--;
- Info sub = *it;
- if (used[sub.i][sub.j]) {
- fix.pop_back();
- }
- else {
- break;
- }
- }
- return;
- }
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- srand(time(NULL));
- ll t = 1;
- cin >> t;
- while (t--) {
- ll b, w;
- cin >> n >> m >> b >> w;
- vector<vector<char>> a(4 * n, vector<char>(4 * m, '.'));
- if (w == 0 || b == 0) {
- if (w == 0 && b == 0) {
- for (ll i = 0; i < 4 * n; i++) {
- for (ll j = 0; j < 4 * m; j++) {
- cout << a[i][j];
- }
- cout << '\n';
- }
- continue;
- }
- else if (b == 0) {
- for (ll i = 0; i < 4 * n; i++) {
- for (ll j = 0; j < 4 * m; j++) {
- if (i == 1 && j == 0) {
- cout << 'W';
- }
- else
- cout << a[i][j];
- }
- cout << '\n';
- }
- continue;
- }
- }
- used.assign(4 * n, vector<bool>(4 * m, false));
- vector<Info> black, white;
- a[2 * n][2 * m] = 'B';
- used[2 * n][2 * m] = true;
- b--;
- bool wf = false, bf = false;
- if (b <= black.size()) {
- bf = true;
- }
- if (w <= white.size()) {
- wf = true;
- }
- ll h = 1;
- push(white, 2 * n, 2 * m, n, m, used);
- while (b && w) {
- clean(white);
- clean(black);
- if (b <= black.size()) {
- wf = true;
- }
- else {
- wf = false;
- }
- if (w <= white.size()) {
- bf = true;
- }
- else {
- bf = false;
- }
- if (white.empty()) {
- if (!bf) {
- auto cmp = [&](Info& lhs, Info& rhs) {
- return cnt_of_rank(lhs) < cnt_of_rank(rhs);
- };
- if (black.size() > 6e1) {
- sort(black.begin() + black.size() - 6e1 - 1, black.end(), cmp);
- }
- else {
- sort(all(black), cmp);
- }
- }
- Info sub;
- auto it = black.end();
- it--;
- sub = *it;
- black.pop_back();
- used[sub.i][sub.j] = true;
- a[sub.i][sub.j] = 'B';
- push(white, sub.i, sub.j, n, m, used);
- b--;
- }
- else {
- if (!wf) {
- auto cmp = [&](Info& lhs, Info& rhs) {
- return cnt_of_rank(lhs) < cnt_of_rank(rhs);
- };
- if (white.size() > 6e1) {
- sort(white.begin() + white.size() - 6e1 - 1, white.end(), cmp);
- }
- else {
- sort(all(white), cmp);
- }
- }
- Info sub;
- auto it = white.end();
- it--;
- sub = *it;
- white.pop_back();
- used[sub.i][sub.j] = true;
- a[sub.i][sub.j] = 'W';
- push(black, sub.i, sub.j, n, m, used);
- w--;
- }
- h++;
- }
- if (w) {
- while (w) {
- auto it = white.end();
- it--;
- Info sub = *it;
- white.pop_back();
- if (used[sub.i][sub.j])continue;
- w--;
- a[sub.i][sub.j] = 'W';
- used[sub.i][sub.j] = true;
- }
- }
- if (b) {
- while (b) {
- auto it = black.end();
- it--;
- Info sub = *it;
- black.pop_back();
- if (used[sub.i][sub.j])
- continue;
- b--;
- a[sub.i][sub.j] = 'B';
- used[sub.i][sub.j] = true;
- }
- }
- for (ll i = 0; i < 4 * n; i++) {
- for (ll j = 0; j < 4 * m; j++) {
- cout << a[i][j];
- }
- cout << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement