#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 1003;
char a[N][N];
void solve() {
int n, m;
cin >> n >> m;
auto construct = [&] (int A, int B) {
if(A == 0) {
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
a[i][j] = '-';
return;
}
if(B == 0) {
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
a[i][j] = '+';
return;
}
int have_plus = m - B;
int need_plus_tot = (m + 2) / 2;
int need_plus = need_plus_tot - have_plus;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
a[i][j] = '-';
for(int j = B; j < m; j++)
for(int i = 0; i < n; i++)
a[i][j] = '+';
int pos = 0;
for(int i = 0; i < A; i++) {
for(int j = 0; j < need_plus; j++) {
a[i][pos] = '+';
pos = (pos + 1) % B;
}
}
};
int ans_A = 0, ans_B = 0;
if(n > m) {
ans_A = n, ans_B = 0;
} else {
ans_A = 0, ans_B = m;
}
for(int A = 1; A <= n; A++) {
for(int B = 1; B <= m; B++) {
int have_plus = m - B, have_minus = n - A;
int need_plus_tot = (m + 2) / 2, need_minus_tot = (n + 2) / 2;
int need_plus = max(0, need_plus_tot - have_plus), need_minus = max(0, need_minus_tot - have_minus);
int put_plus = A * need_plus;
int mx_plus_col = (put_plus + B - 1) / B;
if(A - mx_plus_col < need_minus) continue;
if(A + B > ans_A + ans_B) {
ans_A = A, ans_B = B;
}
}
}
cout << ans_A + ans_B << endl;
construct(ans_A, ans_B);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++)
cout << a[i][j];
cout << '\n';
}
}
signed main()
{
IO_OP;
int t;
cin >> t;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
1516 KB |
Output is correct |
2 |
Correct |
37 ms |
2028 KB |
Output is correct |
3 |
Correct |
36 ms |
2156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
1644 KB |
Output is correct |
2 |
Correct |
41 ms |
1900 KB |
Output is correct |
3 |
Correct |
32 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
492 KB |
Output is correct |
5 |
Correct |
43 ms |
1516 KB |
Output is correct |
6 |
Correct |
37 ms |
2028 KB |
Output is correct |
7 |
Correct |
36 ms |
2156 KB |
Output is correct |
8 |
Correct |
43 ms |
1644 KB |
Output is correct |
9 |
Correct |
41 ms |
1900 KB |
Output is correct |
10 |
Correct |
32 ms |
1644 KB |
Output is correct |
11 |
Correct |
12 ms |
620 KB |
Output is correct |
12 |
Correct |
33 ms |
1900 KB |
Output is correct |
13 |
Correct |
35 ms |
2028 KB |
Output is correct |
14 |
Correct |
26 ms |
1772 KB |
Output is correct |
15 |
Correct |
42 ms |
2284 KB |
Output is correct |
16 |
Correct |
32 ms |
1900 KB |
Output is correct |
17 |
Correct |
14 ms |
1388 KB |
Output is correct |