Submission #898074

#TimeUsernameProblemLanguageResultExecution timeMemory
898074vjudge1Red-blue table (IZhO19_stones)C++17
11 / 100
906 ms42112 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e3, X = 54;

mt19937 rng(time(nullptr));

int t, n, m, ans, idx, r[N], c[N];
vector<string> a[X];
bool bn, bm;

int f(int x) {
  for (int i = 0; i < n; i++) {
    r[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    c[i] = 0;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[x][i][j] == '+') r[i]++;
      else c[j]++;
    }
  }

  int y = 0;
  for (int i = 0; i < n; i++) {
    if (bm) y += (r[i] + bm > (m+1)/2);
    else y += (r[i] > m/2);
  }
  for (int i = 0; i < m; i++) {
    if (bn) y += (c[i] + bn > (n+1)/2);
    else y += (c[i] > n/2);
  }
  return y;
}

/*
void debug(int x) {
  cout << f(x) << "\n";
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << a[x][i][j];
    }
    cout << "\n";
  }
  cout << "\n";
}
*/

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> t;
  while (t--) {
    bn = bm = 0;
    cin >> n >> m;

    if (n > 1 && n%2 == 0) {
      n--;
      bn = 1;
    }
    if (m > 1 && m%2 == 0) {
      m--;
      bm = 1;
    }

    ans = 0;

    // mis 4 construcciones
    a[0].clear();
    a[0].resize(n, string(m, '-'));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (j <= m/2) a[0][i][j] = '+';
      }
    }
    int y = f(0);
    if (y > ans) {
      ans = y;
      idx = 0;
    }

    // ---
    a[1].clear();
    a[1].resize(n, string(m, '+'));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (i <= n/2) a[1][i][j] = '-';
      }
    }
    y = f(1);
    if (y > ans) {
      ans = y;
      idx = 1;
    }

    // ---
    a[2].clear();
    a[2].resize(n, string(m, '+'));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if ((i <= n/2 && j < m/2) || (i >= n/2 && j > m/2)) a[2][i][j] = '-';
      }
    }
    y = f(2);
    if (y > ans) {
      ans = y;
      idx = 2;
    }

    // ---
    a[3].clear();
    a[3].resize(n, string(m, '-'));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if ((i < n/2 && j <= m/2) || (i > n/2 && j >= m/2)) a[3][i][j] = '+';
      }
    }
    y = f(3);
    if (y > ans) {
      ans = y;
      idx = 3;
    }

    // X construcciones random
    for (int x = 0; x+4 < X; x++) {
      a[x+4].clear();
      a[x+4].resize(n, string(m, '+'));

      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (rng() % 2) a[x+4][i][j] = '-';
        }
      }

      int y = f(x+4);
      if (y > ans) {
        ans = y;
        idx = x+4;
      }
    }

    cout << ans << "\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << a[idx][i][j];
      }
      if (bm) cout << '+';
      cout << "\n";
    }
    if (bn) {
      for (int i = 0; i <= m; i++) {
        cout << '-';
      }
      cout << "\n";
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...