#include <bits/stdc++.h>
using namespace std;
const int nx=1e3+5;
int n, m, ans[nx][nx], s, cnt[nx], res[nx][nx], cur, thm, thn;
void solve()
{
cin>>n>>m;
cur=0;
thn=(n+2)/2;
thm=(m+2)/2;
//cout<<"th "<<thn<<' '<<thm<<'\n';
for (int t=0; t<=n; t++)
{
int cs=t+(m-thm);
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) ans[i][j]=0;
for (int i=1; i<=thm; i++) cnt[i]=n-t;
for (int i=thm+1; i<=m; i++) cnt[i]=n-thn;
for (int i=1; i<=t; i++) for (int j=1; j<=thm; j++) ans[i][j]=1;
int idx=thm+1, lst=1;
for (int i=1; i<=thm; i++)
{
while (cnt[i]<thn&&idx<=m)
{
if (cnt[idx]==0||lst>t) idx++, lst=1;
else
{
swap(ans[lst][i], ans[lst][idx]);
cnt[idx]--;
cnt[i]++;
lst++;
}
}
if (cnt[i]>=thn) cs++;
}
if (t==0) cs=m;
if (cs>cur)
{
cur=cs;
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) res[i][j]=ans[i][j];
}
/*
cout<<"show "<<t<<' '<<cs<<'\n';
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++) cout<<ans[i][j]<<' ';
cout<<'\n';
}*/
}
cout<<cur<<'\n';
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++) cout<<(res[i][j]?'+':'-');
cout<<'\n';
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
int _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... |