#include <bits/stdc++.h>
using i64 = long long;
bool check(int red, int blue, int n, int m) {
if (red == 0 || blue == 0) {
return true;
}
int part = std::max(0, (m + 2) / 2 - (m - blue));
int part2 = std::max(0, (n + 2)/ 2 - (n - red));
if (part <= blue) {
int slots = (part * red + blue - 1) / blue;
if (slots + part2 <= red) {
return true;
}
}
return false;
}
void solve() {
int n, m;
std::cin >> n >> m;
int x = 0, y = 0;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (check(i, j, n, m) == true && x + y < i + j) {
x = i;
y = j;
}
}
}
std::cout << x + y << "\n";
int col = 0;
int part = std::max(0, (m + 2) / 2 - (m - y));
for (int i = 0; i < x; i++) {
std::string s;
s.resize(m);
for (int j = 0; j < m; j++) {
s[j] = '-';
}
for (int j = 0; j < part; j++) {
s[col] = '+';
col = (col + 1) % y;
}
for (int j = y; j < m; j++) {
s[j] = '+';
}
std::cout << s << "\n";
}
for (int i = x; i < n; i++) {
std::string s;
s.resize(m);
for (int j = 0; j < m; j++) {
s[j] = '-';
}
std::cout << s << "\n";
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1372 KB |
Output is correct |
2 |
Correct |
8 ms |
1372 KB |
Output is correct |
3 |
Correct |
7 ms |
1248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1376 KB |
Output is correct |
2 |
Correct |
7 ms |
1116 KB |
Output is correct |
3 |
Correct |
6 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
10 ms |
1372 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
7 ms |
1248 KB |
Output is correct |
8 |
Correct |
9 ms |
1376 KB |
Output is correct |
9 |
Correct |
7 ms |
1116 KB |
Output is correct |
10 |
Correct |
6 ms |
1112 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
7 ms |
1068 KB |
Output is correct |
13 |
Correct |
7 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
9 ms |
1372 KB |
Output is correct |
16 |
Correct |
7 ms |
1112 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |