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;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int N, M;
cin >> N >> M;
if (N == 4 && M == 3) {
cout << "5\n++-\n++-\n++-\n++-\n";
} else if (N == 3 && M == 4) {
cout << "5\n----\n----\n++++\n";
} else if (N <= 2 || M <= 2) {
cout << max(N, M) << "\n";
for (int i = 0; i < N; i++, cout << "\n") {
for (int j = 0; j < M; j++) {
cout << "-+"[N > M];
}
}
} else if (N % 2 == 0 && M % 2 == 0 && min(N, M) * 2 <= max(N, M) + 6) {
cout << N + M - 3 << "\n";
if (N > M) {
string rot(M - 3, '+');
fill(rot.begin(), rot.begin() + M / 2 - 1, '-');
for (int i = 0; i < N; i++) {
cout << "+++" << rot << "\n";
rotate(rot.begin(), rot.begin() + M / 2 - 1, rot.end());
}
} else {
string rot(N - 3, '-');
fill(rot.begin(), rot.begin() + N / 2 - 1, '+');
vector<string> s(N, string(M, 0));
for (int j = 0; j < M; j++) {
s[0][j] = s[1][j] = s[2][j] = '-';
for (int i = 3; i < N; i++) {
s[i][j] = rot[i - 3];
}
rotate(rot.begin(), rot.begin() + N / 2 - 1, rot.end());
}
for (int i = 0; i < N; i++) {
cout << s[i] << "\n";
}
}
} else {
int H = N - (2 - N % 2), W = M - (2 - M % 2);
cout << H + W << "\n";
for (int i = 0; i < N; i++, cout << "\n") {
for (int j = 0; j < M; j++) {
cout << "-+"[i < H && (j >= W || (i + j) % 2)];
}
}
}
}
}
# | 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... |