제출 #1092548

#제출 시각아이디문제언어결과실행 시간메모리
1092548juicyRed-blue table (IZhO19_stones)C++17
100 / 100
27 ms2396 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  int t; cin >> t;
  while (t--) {
    int n, m; cin >> n >> m;
    bool flip = 0;
    if (n > m) {
      swap(n, m);
      flip = 1;
    }
    vector<int> cnt(m), ord(m); iota(ord.begin(), ord.end(), 0);
    int cut = (n - 1) / 2, need = m / 2 + 1;
    int x = m * cut / need;
    cout << m + x << "\n";
    vector a(n, vector<char>(m, '-'));
    for (int i = 0; i < x; ++i) {
      sort(ord.begin(), ord.end(), [&](int a, int b) {
        return cnt[a] < cnt[b];
      });
      for (int j = 0; j < need; ++j) {
        a[i][ord[j]] = '+';
        ++cnt[ord[j]];
      }
    }
    if (flip) {
      for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
          cout << char(a[j][i] ^ '+' ^ '-');
        }
        cout << "\n";
      }
    } else {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
          cout << a[i][j];
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
#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...