답안 #197151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197151 2020-01-19T10:11:05 Z IOrtroiii Red-blue table (IZhO19_stones) C++14
11 / 100
32 ms 1400 KB
#include <bits/stdc++.h>

using namespace std;

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

const string cs = "+-";

void solve() {
   int N, M;
   cin >> N >> M;
   auto print = [&](int ansRow, int ansCol, bool f) {
      assert(0 <= ansRow && ansRow <= N);
      assert(0 <= ansCol && ansCol <= M);
      cout << ansRow + ansCol << "\n";
      for (int i = 0; i < N; ++i) {
         for (int j = 0; j < M; ++j) {
            if (i < ansRow && j < ansCol) {
               cout << cs[(i ^ j ^ f) & 1];
            } else if (i < ansRow) {
               cout << cs[0];
            } else if (j < ansCol) {
               cout << cs[1];
            } else {
               cout << cs[rng() & 1];
            }
         }
         cout << "\n";
      }
   };
   for (int ans = N + M; ans >= 0; --ans) {
      for (int ansRow = max(0, ans - M); ansRow <= min(N, ans); ++ansRow) {
         int ansCol = ans - ansRow;
         if (min(ansCol, ansRow) == 0) {
            print(ansRow, ansCol, 0);
            return;
         }
         // f = 0
         {
            int worstRow;
            if (ansCol % 2) {
               worstRow = (ansRow >= 2) ? -1 : 1;
            } else {
               worstRow = 0;
            }
            int worstCol;
            if (ansRow % 2) {
               worstCol = -1;
            } else {
               worstCol = 0;
            }
            if (worstRow + M - ansCol > 0 && worstCol + N - ansRow > 0) {
               print(ansRow, ansCol, 0);
               return;
            }
         }
         // f = 1
         {
            int worstRow = (ansCol % 2) ? -1 : 0;
            int worstCol = (ansRow % 2 && ansCol >= 2) ? -1 : 1;
            if (ansRow % 2 == 0) {
               worstCol = 0;
            }
            if (worstRow + M - ansCol > 0 && worstCol + N - ansRow > 0) {
               print(ansRow, ansCol, 1);
            }
         }
      }
   }
   assert(false);
}

int main() {
   ios_base::sync_with_stdio(false);
   int T;
   cin >> T;
   while (T--) {
      solve();
   }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 4 < 5
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Wrong answer in test 4 3: 4 < 5
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 4 < 5
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1400 KB Output is correct
2 Correct 27 ms 1316 KB Output is correct
3 Correct 32 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 1400 KB Wrong answer in test 4 4: 4 < 5
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 4 < 5