#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
typedef pair <int, int> pi;
int t, n, m, a, b;
char c[MAXN][MAXN];
bool moze (int x, int y) {
if (x == 0 || y == 0) return 1;
int ost = x * y - max(a - (m - y), 0) * x;
return ost / y + n - x >= b;
}
void build (int x, int y) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i >= x) c[i][j] = '-';
if (j >= y) c[i][j] = '+';
}
}
if (y == 0) return;
int br = max(a - (m - y), 0), curr = 0;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
c[i][(curr + j) % y] = j < br ? '+' : '-';
}
curr = (curr + br) % y;
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> m;
a = m / 2 + 1;
b = n / 2 + 1;
int sol = 0;
pi best = {0, 0};
for (int x = 0; x <= n; x++) {
for (int y = 0; y <= m; y++) {
if (x + y > sol && moze(x, y)) {
sol = x + y;
best = {x, y};
}
}
}
build(best.first, best.second);
cout << sol << '\n';
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << c[i][j];
}
cout << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
1516 KB |
Output is correct |
2 |
Correct |
44 ms |
2028 KB |
Output is correct |
3 |
Correct |
35 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1516 KB |
Output is correct |
2 |
Correct |
34 ms |
2028 KB |
Output is correct |
3 |
Correct |
31 ms |
1644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
42 ms |
1516 KB |
Output is correct |
6 |
Correct |
44 ms |
2028 KB |
Output is correct |
7 |
Correct |
35 ms |
2156 KB |
Output is correct |
8 |
Correct |
40 ms |
1516 KB |
Output is correct |
9 |
Correct |
34 ms |
2028 KB |
Output is correct |
10 |
Correct |
31 ms |
1644 KB |
Output is correct |
11 |
Correct |
11 ms |
748 KB |
Output is correct |
12 |
Correct |
33 ms |
1900 KB |
Output is correct |
13 |
Correct |
35 ms |
2156 KB |
Output is correct |
14 |
Correct |
29 ms |
1772 KB |
Output is correct |
15 |
Correct |
42 ms |
2284 KB |
Output is correct |
16 |
Correct |
31 ms |
1900 KB |
Output is correct |
17 |
Correct |
14 ms |
1320 KB |
Output is correct |