#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define threesum cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define int long long
#define double long double
#define pii pair<int, int>
#define ppp pair<int, pii>
#define dout cout << fixed << setprecision(15)
#define mid ((l + r) / 2)
#define lc (2 * id)
#define rc (lc + 1)
const int maxn = 2e5 + 10, maxm = 5e3 + 10, oo = 1e18 + 10, lg = 18, sq = 350, mod = 998244353;
int n, m;
bool ans[maxm][maxm];
signed main()
{
threesum;
int t;
cin >> t;
while(t--){
cin >> n >> m;
for (int i = 1; i <= n;i++)
for (int j = 1; j <= m;j++)
ans[i][j] = 0;
if(n >= m){
int k = n + ((n * ((m + 1) / 2 - 1)) / ((n / 2) + 1));
cout << k << "\n";
set<pii> s;
for (int i = 1; i <= n;i++)
s.insert({0, i});
for (int j = 1; j <= k - n;j++){
int x = n / 2 + 1;
while(x--){
auto [cnt, i] = *s.begin();
s.erase({cnt, i});
ans[i][j] = 1;
s.insert({cnt + 1, i});
}
}
for (int i = 1; i <= n;i++){
for (int j = 1; j <= m;j++)
cout << (ans[i][j] ? '-' : '+');
cout << "\n";
}
}
else{
int k = m + ((m * ((n + 1) / 2 - 1)) / ((m / 2) + 1));
cout << k << "\n";
set<pii> s;
for (int i = 1; i <= m;i++)
s.insert({0, i});
for (int i = 1; i <= k - m;i++){
int x = m / 2 + 1;
while(x--){
auto [cnt, j] = *s.begin();
s.erase({cnt, j});
ans[i][j] = 1;
s.insert({cnt + 1, j});
}
}
for (int i = 1; i <= n;i++){
for (int j = 1; j <= m;j++)
cout << (ans[i][j] ? '+' : '-');
cout << "\n";
}
}
}
}
/*
++-
++-
+++
++-+-
+++--
+++--
++--+
++-++
n*n = n +
*/
# | 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... |