Advertisement
ivnikkk

Untitled

Feb 23rd, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.45 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("unroll-loops")
  3. #pragma GCC target("avx2")
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #define debug(x) cerr<<" smotri huinyi : "<<#x<<' '<<x<<'\n';
  6. #include "bits/stdc++.h"
  7. //#include "geometry.h"
  8. //#include "data_structure.h"
  9. using namespace std;
  10. using namespace chrono;
  11. #define all(a) a.begin(), a.end()
  12. #define allr(a) a.rbegin(), a.rend()
  13. #define sqrt(x) sqrtl(x)
  14. mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
  15. typedef long long ll;
  16. typedef long double ld;
  17. signed main() {
  18. #ifdef _DEBUG
  19.     freopen("input.txt", "r", stdin);
  20.     freopen("output.txt", "w", stdout);
  21. #endif
  22.     srand(time(NULL));
  23.     ll t = 1;
  24.     cin >> t;
  25.     while (t--) {
  26.         ll n, m, b, w;
  27.         cin >> n >> m >> b >> w;
  28.         vector<vector<char>> a(4 * n, vector<char>(4 * m));
  29.         a[0][0] = 'B';
  30.         for (ll i = 0; i < 4 * n; i++){
  31.             for (ll j = 0; j < 4 * m; j++){
  32.                 a[i][j] = 'B';
  33.                 if (i != 0 && a[i - 1][j] == 'B'){
  34.                     a[i][j] = 'W';
  35.                 }
  36.                 if (j != 0 && a[i][j - 1] == 'B'){
  37.                     a[i][j] = 'W';
  38.                 }
  39.             }
  40.         }
  41.  
  42.         ll cntb = 0, cntw = 0;
  43.         vector<vector<bool>>used(4 * n, vector<bool>(4 * m, 0));
  44.         if (b == 0) {
  45.             if (w != 0) {
  46.                 used[0][1] = true;
  47.             }
  48.             for (ll i = 0; i < 4 * n; i++) {
  49.                 for (ll j = 0; j < 4 * m; j++) {
  50.                     if (used[i][j]){
  51.                         cout << a[i][j];
  52.                     }
  53.                     else{
  54.                         cout << '.';
  55.                     }
  56.                 }
  57.                 cout << '\n';
  58.             }
  59.             continue;
  60.         }
  61.         a[1][4 * m - 1] = '.';
  62.         for (int i = 1; i < 4 * m - 2; i++){
  63.             if (cntb == b)
  64.                 break;
  65.             if (a[1][i] == 'B'){
  66.                 cntb++;
  67.                 used[1][i] = true;
  68.             }
  69.             else{
  70.                 cntw++;
  71.                 used[1][i] = true;
  72.             }
  73.         }
  74.         for (ll i = 2; i < 4 * n - 2; i++) {
  75.             for(ll j = 1; j < 4 * m - 2; j += 4) {
  76.                 if (cntw < w && !used[i][j] && a[i][j] == 'W' && a[i - 1][j] == 'B' && used[i - 1][j]) {
  77.                     cntw++;
  78.                     used[i][j] = true;
  79.                 }
  80.                 if (cntb < b && !used[i][j] && a[i][j] == 'B' && a[i - 1][j] == 'W' && used[i - 1][j]) {
  81.                     cntb++;
  82.                     used[i][j] = true;
  83.                 }
  84.             }
  85.         }
  86.  
  87.         for (ll i = 0; i < 4 * n; i++) {
  88.             for (ll j = 0; j < 4 * m; j++) {
  89.                 if (!used[i][j] && a[i][j] == 'B'){
  90.                     used[i][j] = true;
  91.                     a[i][j] = '.';
  92.                 }
  93.             }
  94.         }
  95.         for (ll i = 0; i < 4 * n; i++) {
  96.             for (ll j = 0; j < 4 * m; j++) {
  97.                 if (!used[i][j]) {
  98.                     bool ok = false;
  99.                     if (i >= 0 && a[i - 1][j] == 'B'){
  100.                         cntw++;
  101.                         used[i][j] = true;
  102.                         ok = true;
  103.                         if (cntw == w)
  104.                             goto print;
  105.                     }
  106.                     if (!ok && j >= 0 && a[i][j - 1] == 'B') {
  107.                         cntw++;
  108.                         used[i][j] = true;
  109.                         ok = true;
  110.                         if (cntw == w)
  111.                             goto print;
  112.                     }
  113.                     if (!ok && j + 1 < 4 * m && a[i][j + 1] == 'B' ){
  114.                         cntw++;
  115.                         used[i][j] = true;
  116.                         ok = true;
  117.                         if (cntw == w)
  118.                             goto print;
  119.                     }
  120.                     if (!ok && i + 1 < 4 * n && a[i + 1][j] == 'B') {
  121.                         cntw++;
  122.                         used[i][j] = true;
  123.                         ok = true;
  124.                         if (cntw == w)
  125.                             goto print;
  126.                     }
  127.                 }
  128.             }
  129.         }
  130. print:
  131.         for (ll i = 0; i < 4 * n; i++) {
  132.             for (ll j = 0; j < 4 * m; j++) {
  133.                 if (used[i][j])
  134.                     cout << a[i][j];
  135.                 else
  136.                     cout << '.';
  137.             }
  138.             cout << '\n';
  139.         }
  140.     }
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement