#include<bits/stdc++.h>
using namespace std;
const int MAXN=1024;
int cnt[MAXN];
char table[MAXN][MAXN];
void solve()
{
int n,m,n1,m1;
cin>>n>>m;
n1=n/2+1;m1=m/2+1;
int ans1=n+(n*m-n*m1)/n1;
int ans2=m+(n*m-m*n1)/m1;
cout<<max(ans1,ans2)<<endl;
if(ans1>ans2)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
table[i][j]='+';
}
cnt[i]=0;
}
for(int i=1;i<=ans1-n;i++)
{
vector<pair<int,int> >cnts;
for(int j=1;j<=n;j++)
{
cnts.push_back({cnt[j],j});
}
sort(cnts.begin(),cnts.end());
for(int j=0;j<n1;j++)
{
cnt[cnts[j].second]++;
table[cnts[j].second][i]='-';
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<table[i][j];
}
cout<<'\n';
}
}
else
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
table[i][j]='-';
cnt[j]=0;
}
}
for(int i=1;i<=ans2-m;i++)
{
vector<pair<int,int> >cnts;
for(int j=1;j<=m;j++)
{
cnts.push_back({cnt[j],j});
}
sort(cnts.begin(),cnts.end());
for(int j=0;j<m1;j++)
{
cnt[cnts[j].second]++;
table[i][cnts[j].second]='+';
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<table[i][j];
}
cout<<'\n';
}
}
}
int main()
{
int t;
cin>>t;
while(t--)solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
3 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
1516 KB |
Output is correct |
2 |
Correct |
82 ms |
2156 KB |
Output is correct |
3 |
Correct |
81 ms |
2156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
1516 KB |
Output is correct |
2 |
Correct |
74 ms |
1900 KB |
Output is correct |
3 |
Correct |
65 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 |
3 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
5 |
Correct |
81 ms |
1516 KB |
Output is correct |
6 |
Correct |
82 ms |
2156 KB |
Output is correct |
7 |
Correct |
81 ms |
2156 KB |
Output is correct |
8 |
Correct |
79 ms |
1516 KB |
Output is correct |
9 |
Correct |
74 ms |
1900 KB |
Output is correct |
10 |
Correct |
65 ms |
1644 KB |
Output is correct |
11 |
Correct |
21 ms |
620 KB |
Output is correct |
12 |
Correct |
67 ms |
1900 KB |
Output is correct |
13 |
Correct |
71 ms |
2156 KB |
Output is correct |
14 |
Correct |
55 ms |
1800 KB |
Output is correct |
15 |
Correct |
93 ms |
2304 KB |
Output is correct |
16 |
Correct |
66 ms |
1900 KB |
Output is correct |
17 |
Correct |
29 ms |
1388 KB |
Output is correct |