#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;
int H = N - 2 + N % 2, W = M - 2 + M % 2;
if (N == 4 && M == 4) {
cout << "5\n+++-\n+++-\n+++-\n+++-\n";
} else if (H + W < max(N, M) + (min(N, M) + 1) / 2) {
if (N > M) {
if (M <= 2) {
cout << N << "\n";
for (int i = 0; i < N; i++) {
cout << string(M, '+') << "\n";
}
} else if (M <= 4) {
cout << N + 1 << "\n";
for (int i = 0; i < N; i++) {
cout << string(M - 1, '+') << "-\n";
}
} else {
cout << N + (M + 1) / 2 << "\n";
vector<string> s(N, string(M, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < M / 2; j++) {
s[i][j] = '+';
}
for (int j = M / 2; j < M; j++) {
s[i][j] = (j - M / 2) % ((M + 1) / 2) == i % ((M + 1) / 2) ? '+' : '-';
}
}
for (int i = 0; i < N; i++) {
cout << s[i] << "\n";
}
}
} else {
if (N <= 2) {
cout << M << "\n";
for (int i = 0; i < N; i++) {
cout << string(M, '-') << "\n";
}
} else if (N <= 4) {
cout << M + 1 << "\n";
for (int i = 0; i < N; i++) {
cout << (i < N - 1 ? string(M, '-') : string(M, '+')) << "\n";
}
} else {
cout << (N + 1) / 2 + M << "\n";
vector<string> s(N, string(M, 0));
for (int j = 0; j < M; j++) {
for (int i = 0; i < N / 2; i++) {
s[i][j] = '-';
}
for (int i = N / 2; i < N; i++) {
s[i][j] = (i - N / 2) % ((N + 1) / 2) == j % ((N + 1) / 2) ? '-' : '+';
}
}
for (int i = 0; i < N; i++) {
cout << s[i] << "\n";
}
}
}
} else {
cout << H + W << "\n";
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (i < H && j < W) {
cout << "+-"[(i + j) % 2];
} else if (i < H) {
cout << "+";
} else {
cout << "-";
}
}
cout << "\n";
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1368 KB |
Output is correct |
2 |
Correct |
15 ms |
1112 KB |
Output is correct |
3 |
Correct |
13 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1372 KB |
Output is correct |
2 |
Correct |
13 ms |
1112 KB |
Output is correct |
3 |
Correct |
12 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
16 ms |
1368 KB |
Output is correct |
6 |
Correct |
15 ms |
1112 KB |
Output is correct |
7 |
Correct |
13 ms |
1116 KB |
Output is correct |
8 |
Correct |
16 ms |
1372 KB |
Output is correct |
9 |
Correct |
13 ms |
1112 KB |
Output is correct |
10 |
Correct |
12 ms |
1112 KB |
Output is correct |
11 |
Incorrect |
4 ms |
600 KB |
Wrong answer in test 26 8: 30 < 31 |
12 |
Halted |
0 ms |
0 KB |
- |