Submission #348427

# Submission time Handle Problem Language Result Execution time Memory
348427 2021-01-15T02:00:18 Z casperwang Red-blue table (IZhO19_stones) C++14
100 / 100
78 ms 3436 KB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

int t, n, m;
vector<vector<char>> A, B;
vector <pii> cnt;
int ansA, ansB;

void init() {
  A.clear(), B.clear();
  A.resize(n), B.resize(n);
  for (int i = 0; i < n; i++)
    A[i].resize(m), B[i].resize(m);
  ansA = n, ansB = m;
}

void check() {
  int tmp = ansA;
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < m; j++) {
      if (A[i][j] == '+') c++;
    }
    if (c * 2 > m) tmp--;
  }
  for (int i = 0; i < m; i++) {
    int c = 0;
    for (int j = 0; j < n; j++) {
      if (A[j][i] == '-') c++;
    }
    if (c * 2 > n) tmp--;
  }
  assert(!tmp);
  tmp = ansB;
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < m; j++) {
      if (B[i][j] == '+') c++;
    }
    if (c * 2 > m) tmp--;
  }
  for (int i = 0; i < m; i++) {
    int c = 0;
    for (int j = 0; j < n; j++) {
      if (B[j][i] == '-') c++;
    }
    if (c * 2 > n) tmp--;
  }
  assert(!tmp);
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    init();
    cnt.clear(), cnt.resize(n);
    for (int i = 0; i < n; i++)
      cnt[i] = pii(0, i);
    for (int i = 0; i < m; i++) {
      int c = (n+2)/2;
      sort(All(cnt));
      for (auto &[v, j] : cnt) {
        if (c > 0 && v < (m-1)/2) {
          A[j][i] = '-';
          v++, c--;
        } else {
          A[j][i] = '+';
        }
      }
      if (!c) ansA++;
    }
    cnt.clear(), cnt.resize(m);
    for (int i = 0; i < m; i++)
      cnt[i] = pii(0, i);
    for (int i = 0; i < n; i++) {
      int c = (m+2)/2;
      sort(All(cnt));
      for (auto &[v, j] : cnt) {
        if (c > 0 && v < (n-1)/2) {
          B[i][j] = '+';
          v++, c--;
        } else {
          B[i][j] = '-';
        }
      }
      if (!c) ansB++;
    }
    check();
    if (ansA > ansB) {
      cout << ansA << '\n';
      for (auto v : A) {
        for (char c : v) {
          cout << c;
        }
        cout << '\n';
      }
    } else {
      cout << ansB << '\n';
      for (auto v : B) {
        for (char c : v) {
          cout << c;
        }
        cout << '\n';
      }
    }
  }
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:70:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   70 |       for (auto &[v, j] : cnt) {
      |                  ^
stones.cpp:86:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   86 |       for (auto &[v, j] : cnt) {
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 1516 KB Output is correct
2 Correct 71 ms 2668 KB Output is correct
3 Correct 71 ms 2700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 1516 KB Output is correct
2 Correct 66 ms 2284 KB Output is correct
3 Correct 63 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 76 ms 1516 KB Output is correct
6 Correct 71 ms 2668 KB Output is correct
7 Correct 71 ms 2700 KB Output is correct
8 Correct 72 ms 1516 KB Output is correct
9 Correct 66 ms 2284 KB Output is correct
10 Correct 63 ms 1772 KB Output is correct
11 Correct 20 ms 640 KB Output is correct
12 Correct 61 ms 2028 KB Output is correct
13 Correct 63 ms 1900 KB Output is correct
14 Correct 47 ms 1388 KB Output is correct
15 Correct 78 ms 3436 KB Output is correct
16 Correct 59 ms 2560 KB Output is correct
17 Correct 26 ms 1388 KB Output is correct