Submission #898304

#TimeUsernameProblemLanguageResultExecution timeMemory
898304vjudge1Red-blue table (IZhO19_stones)C++17
100 / 100
1655 ms3412 KiB
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()

const int N = 1e3;

int t, n, m, x, ans, r[N], c[N];
char a[2][N][N];
string b[3];

int f() {
  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[1][i][j] == '+') r[i]++;
      else c[j]++;
    }
  }

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

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

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

      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          a[1][i][j] = '+';
        }
      }

      vector<int> cnt(n, m);
      for (int j = 0; j < m; j++) {
        vector<pair<int, int>> pos;
        for (int i = 0; i < n; i++) {
          pos.push_back(make_pair(-cnt[i], i));
        }
        sort(all(pos));

        for (int i = 0; i <= n/2; i++) {
          int y = -pos[i].first;
          if (y-1 <= m/2) continue;
          cnt[pos[i].second]--;
          a[1][pos[i].second][j] = '-';
        }
      }

      x = f();
      if (x > ans) {
        ans = x;
        swap(a[0], a[1]);
      }

      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          a[1][i][j] = '-';
        }
      }
      
      //vector<int> cnt;
      cnt.clear();
      cnt.resize(m, n);
      for (int i = 0; i < n; i++) {
        vector<pair<int, int>> pos;
        for (int j = 0; j < m; j++) {
          pos.push_back(make_pair(-cnt[j], j));
        }
        sort(all(pos));

        for (int j = 0; j <= m/2; j++) {
          int y = -pos[j].first;
          if (y-1 <= n/2) continue;
          cnt[pos[j].second]--;
          a[1][i][pos[j].second] = '+';
        }
      }

      x = f();
      if (x > ans) {
        ans = x;
        swap(a[0], a[1]);
      }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        a[1][i][j] = '+';
      }
    }
    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[1][i][j] = '-';
      }
    }
    x = f();
    if (x > ans) {
      ans = x;
      swap(a[0], a[1]);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        a[1][i][j] = '+';
      }
    }
    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[1][i][j] = '+';
      }
    }
    x = f();
    if (x > ans) {
      ans = x;
      swap(a[0], a[1]);
    }

    cout << ans << "\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << a[0][i][j];
      }
      cout << "\n";
    }

    if (n%2 == 1 && m%2 == 1) {
      
    }
    else if (n == m) {

    }
    else if (n%2 == 0 && m%2 == 1) {

    }
    else if (n%2 == 1 && m%2 == 0) {

    }
    else if (n%2 == 1 && m%2 == 1) {

    }
  }
}


/*
--++++
++--++
++++--
------
------

--++++
----++
------
++----
++++--
*/
#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...