This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |