제출 #197151

#제출 시각아이디문제언어결과실행 시간메모리
197151IOrtroiiiRed-blue table (IZhO19_stones)C++14
11 / 100
32 ms1400 KiB
#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();
   }
}
#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...