#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)];
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Wrong answer in test 3 6: 6 < 7 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Wrong answer in test 3 6: 6 < 7 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1368 KB |
Output is correct |
2 |
Correct |
15 ms |
1344 KB |
Output is correct |
3 |
Correct |
28 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
1372 KB |
Output is correct |
2 |
Correct |
16 ms |
1116 KB |
Output is correct |
3 |
Correct |
22 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Wrong answer in test 3 6: 6 < 7 |
4 |
Halted |
0 ms |
0 KB |
- |