이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |