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;
- inline int readChar();
- template <class T = int> inline T readInt();
- template <class T> inline void writeInt(T x, char end = 0);
- inline void writeChar(int x);
- inline void writeWord(const char* s);
- /** Read */
- static const int buf_size = 4096;
- inline int getChar() {
- static char buf[buf_size];
- static int len = 0, pos = 0;
- if (pos == len)
- pos = 0, len = fread(buf, 1, buf_size, stdin);
- if (pos == len)
- return -1;
- return buf[pos++];
- }
- inline int readChar() {
- int c = getChar();
- while (c <= 32)
- c = getChar();
- return c;
- }
- template <class T>
- inline T readInt() {
- int s = 1, c = readChar();
- T x = 0;
- if (c == '-')
- s = -1, c = getChar();
- while ('0' <= c && c <= '9')
- x = x * 10 + c - '0', c = getChar();
- return s == 1 ? x : -x;
- }
- /** Write */
- static int write_pos = 0;
- static char write_buf[buf_size];
- inline void writeChar(int x) {
- if (write_pos == buf_size)
- fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
- write_buf[write_pos++] = x;
- }
- template <class T>
- inline void writeInt(T x, char end) {
- if (x < 0)
- writeChar('-'), x = -x;
- char s[24];
- int n = 0;
- while (x || !n)
- s[n++] = '0' + x % 10, x /= 10;
- while (n--)
- writeChar(s[n]);
- if (end)
- writeChar(end);
- }
- inline void writeWord(const char* s) {
- while (*s)
- writeChar(*s++);
- }
- struct Flusher {
- ~Flusher() {
- if (write_pos)
- fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
- }
- } flusher;
- 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;
- t = readInt();
- while (t--) {
- ll b, w;
- n = readInt();
- m = readInt();
- b = readInt();
- w = readInt();
- 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++) {
- writeChar(a[i][j]);
- }
- writeChar('\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) {
- writeChar('W');
- }
- else
- writeChar(a[i][j]);
- }
- writeChar('\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() > 1e3) {
- sort(black.begin() + black.size() - 1e3-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() > 1e3) {
- sort(white.begin() + white.size()-1e3-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++) {
- writeChar(a[i][j]);
- }
- writeChar('\n');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement