#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
void solve() {
//cout << "f1\n";
ll N,M; cin >> N >> M;
ll ans = 0; ll ac = 0; ll bc = 0;
for (ll a=0; a<=N; a++) {
for (ll b=0;b<=M;b++) { //N=1,M=3 -> a=0,b=3
//need >=(M+1)/2 on a
ll na = max(0LL,M/2+1-(M-b));
ll nb = max(0LL,N/2+1-(N-a));
if ((na*a+nb*b)<=(a*b)) {
if (ans<(a+b)) {
ans = a+b; ac = a; bc = b;
}
}
}
}
cout << ans << "\n";
bool isa[N][M];
for (ll a1 = ac; a1<N; a1++) {
for (ll b1 = 0; b1<M; b1++) {
isa[a1][b1]=0;
}
}
for (ll a1=0;a1<ac;a1++) {
for (ll b1=0; b1<M; b1++) { //now switch the center chunk to be Bs if necessary
isa[a1][b1]=1;
}
}
set<ll> s0;
for (ll b1=0;b1<bc;b1++) {
ll nb = max(0LL,N/2+1-(N-ac));
for (ll t=0;t<nb;t++) {
if (s0.size()==0) {
for (ll a1=0;a1<ac;a1++) {
s0.insert(a1);
}
}
assert(!s0.empty());
ll x0 = *s0.begin(); s0.erase(s0.begin());
isa[x0][b1]=0;
}
}
for (ll a1=0;a1<N;a1++) {
for (ll b1=0;b1<M;b1++) {
cout << (isa[a1][b1] ? "+" : "-");
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
ll T; cin >> T;
while (T--) solve();
}
# | 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... |