Submission #197155

# Submission time Handle Problem Language Result Execution time Memory
197155 2020-01-19T10:35:28 Z IOrtroiii Red-blue table (IZhO19_stones) C++14
100 / 100
67 ms 2424 KB
#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
   int N, M;
   cin >> N >> M;
   bool swapped = false;
   if (N > M) {
      swap(N, M);
      swapped = true;
   }
   int upHalfN = (N / 2) + 1;
   int upHalfM = (M / 2) + 1;
   vector<vector<char>> ans(N, vector<char>(M, '-'));
   int nRow;
   for (nRow = N; nRow >= 0; --nRow) {
      if (nRow * upHalfM <= M * (N - upHalfN)) {
         break;
      }
   }
   vector<int> cnts(nRow, 0);
   for (int i = 0; i < M; ++i) {
      vector<pair<int, int>> cnds;
      for (int j = 0; j < nRow; ++j) {
         cnds.emplace_back(cnts[j], j);
      }
      sort(cnds.begin(), cnds.end());
      cnds.resize(N - upHalfN);
      for (auto v : cnds) {
         int r = v.second;
         ans[r][i] = '+';
         ++cnts[r];
      }
   }
   cout << M + nRow << "\n";
   if (swapped) {
      for (int i = 0; i < M; ++i) {
         for (int j = 0; j < N; ++j) {
            cout << char(ans[j][i] ^ '+' ^ '-');
         }
         cout << "\n";
      }
   } else {
      for (int i = 0; i < N; ++i) {
         for (int j = 0; j < M; ++j) {
            cout << ans[i][j];
         }
         cout << "\n";
      }
   }
}

int main() {
   ios_base::sync_with_stdio(false);
   int T;
   cin >> T;
   while (T--) {
      solve();
   }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 1424 KB Output is correct
2 Correct 65 ms 1756 KB Output is correct
3 Correct 59 ms 2044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1424 KB Output is correct
2 Correct 51 ms 1504 KB Output is correct
3 Correct 52 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 63 ms 1424 KB Output is correct
6 Correct 65 ms 1756 KB Output is correct
7 Correct 59 ms 2044 KB Output is correct
8 Correct 60 ms 1424 KB Output is correct
9 Correct 51 ms 1504 KB Output is correct
10 Correct 52 ms 1368 KB Output is correct
11 Correct 19 ms 636 KB Output is correct
12 Correct 49 ms 1584 KB Output is correct
13 Correct 51 ms 1528 KB Output is correct
14 Correct 37 ms 1092 KB Output is correct
15 Correct 67 ms 2424 KB Output is correct
16 Correct 56 ms 1884 KB Output is correct
17 Correct 24 ms 1016 KB Output is correct