#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;
for (int i=1; i<=thm; i++)
{
while (cnt[i]<thn&&idx<=m)
{
//cout<<"here "<<t<<' '<<i<<' '<<cnt[idx]<<'\n';
if (cnt[idx]==0) idx++;
else
{
for (int k=1; k<=t; k++)
{
if (ans[k][i]&&!ans[k][idx])
{
swap(ans[k][i], ans[k][idx]);
cnt[idx]--;
cnt[i]++;
break;
}
}
}
}
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... |