#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N=1005;
int n,m;
char ans[N][N],b[N][N];
int solve(int n,int m)
{
int res=0;
int del=0;
for(int row_del=0;row_del<=n;row_del++)
{
int can=(m-1)/2;
int need=max(0,n-(n-1)/2-row_del);
if(need==0)
{
if(res<=m+n-row_del)
{
res=m+n-row_del;
del=row_del;
}
continue;
}
int l=0,r=m,x=0;
while(l<=r)
{
int mid=(l+r)/2;
int val=n+1;
if(can) val=(mid+can-1)/can*need;
if(val<=n-row_del)
{
x=mid;
l=mid+1;
}
else r=mid-1;
}
if(res<=n-row_del+x)
{
res=n-row_del+x;
del=row_del;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) ans[i][j]='+';
}
for(int i=n-del+1;i<=n;i++)
{
for(int j=1;j<=m;j++) ans[i][j]='-';
}
set<pii>cur;
cur.clear();
for(int j=1;j<=m;j++) if(del<=n-del) cur.insert(mp(del,j));
for(int i=1;i<=n-del;i++)
{
vector<pii>u;
int can=(m-1)/2;
while(!cur.empty()&&can)
{
can--;
auto x=*cur.rbegin();
cur.erase(x);
int col=x.se;
ans[i][col]='-';
if(x.fi+1>(n-x.fi-1)) continue;
u.push_back(mp(x.fi+1,x.se));
}
for(auto&x:u) cur.insert(x);
}
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
if(solve(n,m)>solve(m,n))
{
cout<<solve(n,m)<<'\n';
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) cout<<ans[i][j];
cout<<'\n';
}
continue;
}
cout<<solve(m,n)<<'\n';
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++) b[j][i]=('+'+'-'-ans[i][j]);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) cout<<b[i][j];
cout<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 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 |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
5 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
1644 KB |
Output is correct |
2 |
Correct |
269 ms |
2944 KB |
Output is correct |
3 |
Correct |
240 ms |
3180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
1644 KB |
Output is correct |
2 |
Correct |
233 ms |
2668 KB |
Output is correct |
3 |
Correct |
223 ms |
2284 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 |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
5 ms |
492 KB |
Output is correct |
5 |
Correct |
246 ms |
1644 KB |
Output is correct |
6 |
Correct |
269 ms |
2944 KB |
Output is correct |
7 |
Correct |
240 ms |
3180 KB |
Output is correct |
8 |
Correct |
219 ms |
1644 KB |
Output is correct |
9 |
Correct |
233 ms |
2668 KB |
Output is correct |
10 |
Correct |
223 ms |
2284 KB |
Output is correct |
11 |
Incorrect |
39 ms |
620 KB |
Wrong answer in test 26 8: 30 < 31 |
12 |
Halted |
0 ms |
0 KB |
- |