#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define all(v) v.begin(),v.end()
#define baraa ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
baraa
auto solve = [&](ll n, ll m, vector<vector<char> > &res, ll &best) {
for (ll a = max(0LL, n - 100); a <= n; a++) {
vector<vector<char> > grid(n, vector<char>(m));
vector<ll> neg[n];
for (ll i = 0; i < n; i++)
for (ll j = 0; j < m; j++)
grid[i][j] = (i < a and j <= m / 2 ? '+' : '-');
ll b = 0;
for (ll j = m - 1; j >= 0; j--) {
ll delta = n / 2 + 1;
for (ll i = 0; i < n; i++)
delta -= (grid[i][j] == '-');
if (delta < 0) {
for (ll i = 0; i < abs(delta); i++)
neg[i].push_back(j);
b++;
} else {
for (ll i = 0; i < n; i++) {
if (delta == 0)break;
if (neg[i].size()) {
delta--;
swap(grid[i][j], grid[i][neg[i].back()]);
neg[i].pop_back();
}
}
}
b += (delta == 0);
}
if (best < a + b) {
best = a + b;
res = grid;
}
}
};
ll t;
cin >> t;
while (t--) {
ll n, m;
cin >> n >> m;
ll best1 = -1, best2 = -1;
vector<vector<char> > g1(n, vector<char>(m)), g2(m, vector<char>(n));
solve(n, m, g1, best1);
solve(m, n, g2, best2);
cout << max(best1, best2) << nl;
if (best2 > best1) {
for (ll i = 0; i < m; i++)
for (ll j = 0; j < n; j++)
g1[j][i] = g2[i][j];
}
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++)
cout << g1[i][j];
cout << nl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |