#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#define ll int
#define ln "\n"
#define ff first
#define ss second
#define ld long double
const ll INF = 1e9;
const ll MOD = 1e9+7;
using namespace std;
void solve(){
ll n, m; cin >> n >> m;
ll nform = n/2+1, mforn=m/2+1;
cout << max((n-nform)*m/mforn+m,(m-mforn)*n/nform+n) << ln;
if ((n-nform)*m/mforn+m>(m-mforn)*n/nform+n){
vector<vector<ll>> ans(n, vector<ll>(m));
multiset<pair<ll, ll>> vac;
for (ll i=0; i<(n-nform)*m/mforn; i++){
vac.insert({0, i});
}
for (ll j=0; j<m; j++){
for (ll i=0; i<n-nform; ++i){
auto cur = *vac.begin();
vac.erase(vac.begin());
assert(ans[cur.ss][j]==0);
ans[cur.ss][j]=2;
vac.insert({cur.ff+1, cur.ss});
}
}
for (ll i=0; i<n; i++){
for (ll j=0; j<m; j++){
cout << (ans[i][j]==2?"+":"-");
}
cout << ln;
}
}else{
vector<vector<ll>> ans(n, vector<ll>(m));
multiset<pair<ll, ll>> vac;
for (ll i=0; i<(m-mforn)*n/nform; i++){
vac.insert({0, i});
}
for (ll i=0; i<n; i++){
for (ll j=0; j<m-mforn; ++j){
auto cur = *vac.begin();
vac.erase(vac.begin());
assert(ans[i][cur.ss]==0);
ans[i][cur.ss]=2;
vac.insert({cur.ff+1, cur.ss});
}
}
for (ll i=0; i<n; i++){
for (ll j=0; j<m; j++){
cout << (ans[i][j]==2?"-":"+");
}
cout << ln;
}
}
}
void setIO(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main(){
setIO();
ll t=1;
cin >> t;
while (t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
388 KB |
Output is correct |
2 |
Correct |
0 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
388 KB |
Output is correct |
2 |
Correct |
0 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
1360 KB |
Output is correct |
2 |
Correct |
49 ms |
3668 KB |
Output is correct |
3 |
Correct |
52 ms |
4148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1504 KB |
Output is correct |
2 |
Correct |
36 ms |
3152 KB |
Output is correct |
3 |
Correct |
36 ms |
2328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
388 KB |
Output is correct |
2 |
Correct |
0 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
42 ms |
1360 KB |
Output is correct |
6 |
Correct |
49 ms |
3668 KB |
Output is correct |
7 |
Correct |
52 ms |
4148 KB |
Output is correct |
8 |
Correct |
45 ms |
1504 KB |
Output is correct |
9 |
Correct |
36 ms |
3152 KB |
Output is correct |
10 |
Correct |
36 ms |
2328 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
35 ms |
2744 KB |
Output is correct |
13 |
Correct |
45 ms |
2132 KB |
Output is correct |
14 |
Correct |
32 ms |
1444 KB |
Output is correct |
15 |
Correct |
48 ms |
5308 KB |
Output is correct |
16 |
Correct |
36 ms |
3980 KB |
Output is correct |
17 |
Correct |
14 ms |
1884 KB |
Output is correct |