#include<bits/stdc++.h>
#define MAXN 1007
using namespace std;
int te,n,m,r,b,best;
int br[MAXN];
pair<int,int> p[MAXN];
char t[MAXN][MAXN];
void construct(int rows,int cols,int r,int b){
int lim=rows-b;
for(int i=1;i<=rows;i++)br[i]=0;
for(int f=1;f<=cols;f++){
for(int i=1;i<=rows;i++){
p[i]={br[i],i};
}
sort(p+1,p+rows+1);
for(int i=1;i<=lim;i++){
t[p[i].second][f]='+';
br[p[i].second]++;
}
for(int i=lim+1;i<=rows;i++){
t[p[i].second][f]='-';
}
}
}
void build(int a,int b){
for(int i=a+1;i<=n;i++){
for(int f=1;f<=m;f++){
t[i][f]='-';
}
}
for(int f=b+1;f<=m;f++){
for(int i=1;i<=n;i++){
t[i][f]='+';
}
}
construct(a,b,max(0, (m/2+b-m)+1 ) , max(0, (n/2+a-n)+1) );
}
bool ok(int A,int B){
int reds=max(0, A* ((m/2+B-m)+1));
int blues=max(0, B* ((n/2+A-n)+1));
return reds+blues<=A*B;
}
void solve(){
cin>>n>>m;
int B=m,A=n;
best=0;
for(A=0;A<=n;A++){
while(B>0 and !ok(A,B))B--;
if(A+B>best){
best=A+B;
r=A; b=B;
}
}
build(r,b);
cout<<best<<"\n";
for(int i=1;i<=n;i++){
for(int f=1;f<=m;f++){
cout<<t[i][f];
}
cout<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>te;
while(te>0){
solve();
te--;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1364 KB |
Output is correct |
2 |
Correct |
28 ms |
1876 KB |
Output is correct |
3 |
Correct |
24 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
1372 KB |
Output is correct |
2 |
Correct |
26 ms |
1876 KB |
Output is correct |
3 |
Correct |
24 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
26 ms |
1364 KB |
Output is correct |
6 |
Correct |
28 ms |
1876 KB |
Output is correct |
7 |
Correct |
24 ms |
2140 KB |
Output is correct |
8 |
Correct |
29 ms |
1372 KB |
Output is correct |
9 |
Correct |
26 ms |
1876 KB |
Output is correct |
10 |
Correct |
24 ms |
1628 KB |
Output is correct |
11 |
Correct |
5 ms |
604 KB |
Output is correct |
12 |
Correct |
20 ms |
1884 KB |
Output is correct |
13 |
Correct |
24 ms |
1972 KB |
Output is correct |
14 |
Correct |
20 ms |
1628 KB |
Output is correct |
15 |
Correct |
38 ms |
2260 KB |
Output is correct |
16 |
Correct |
29 ms |
1884 KB |
Output is correct |
17 |
Correct |
9 ms |
1372 KB |
Output is correct |