답안 #990502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990502 2024-05-30T14:55:38 Z tch1cherin Red-blue table (IZhO19_stones) C++17
100 / 100
20 ms 2396 KB
#include <bits/stdc++.h>
using namespace std;

vector<string> build(int N, int M, int h, int w) {
  vector<string> A(N, string(M, 0));
  if (h > 0) {
    assert(M % 2 == 0);
    string rot(N, '-');
    fill(rot.begin(), rot.begin() + (N + 1) / 2, '+');
    for (int j = 0; j < M; j++) {
      for (int i = 0; i < N; i++) {
        A[i][j] = rot[i];
      }
      rotate(rot.begin(), rot.begin() + (N + 1) / 2, rot.end());
    }
  } else {
    assert(N % 2 == 0);
    string rot(M, '+');
    fill(rot.begin(), rot.begin() + (M + 1) / 2, '-');
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        A[i][j] = rot[j];
      }
      rotate(rot.begin(), rot.begin() + (M + 1) / 2, rot.end());
    }
  }
  return A;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int N, M;
    cin >> N >> M;
    if (N <= 2 || M <= 2) {
      cout << max(N, M) << "\n";
      for (int i = 0; i < N; i++) {
        cout << string(M, "-+"[N > M]) << "\n";
      }
    } else {
      int h, w;
      if (N % 2 && M % 2) {
        h = w = 1;
      } else if (N % 2 != M % 2) {
        if (N % 2 ? N * 2 <= M + 4 : M * 2 <= N + 4)  {
          if (N % 2) {
            h = 2, w = 0;
          } else {
            h = 0, w = 2;
          }
        } else {
          if (N % 2) {
            h = 1, w = 2;
          } else {
            h = 2, w = 1;
          }
        }
      } else {
        if (min(N, M) * 2 <= max(N, M) + 6) {
          if (N > M) {
            h = 0, w = 3;
          } else {
            h = 3, w = 0;
          }
        } else {
          h = w = 2;
        }
      }
      vector<string> A = build(N - h, M - w, h, w);
      cout << N + M - w - h << "\n";
      for (int i = 0; i < N; i++, cout << "\n") {
        for (int j = 0; j < M; j++) {
          cout << (i < N - h && j < M - w ? A[i][j] : "-+"[i < N - h]);
        }
      }
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1372 KB Output is correct
2 Correct 18 ms 1884 KB Output is correct
3 Correct 16 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1368 KB Output is correct
2 Correct 16 ms 1500 KB Output is correct
3 Correct 15 ms 1256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 20 ms 1372 KB Output is correct
6 Correct 18 ms 1884 KB Output is correct
7 Correct 16 ms 1884 KB Output is correct
8 Correct 19 ms 1368 KB Output is correct
9 Correct 16 ms 1500 KB Output is correct
10 Correct 15 ms 1256 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 16 ms 1592 KB Output is correct
13 Correct 16 ms 1624 KB Output is correct
14 Correct 12 ms 1228 KB Output is correct
15 Correct 20 ms 2396 KB Output is correct
16 Correct 16 ms 1860 KB Output is correct
17 Correct 6 ms 1116 KB Output is correct