#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define SPEED \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define ins insert
#define fi first
#define se second
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define sz(x) x.size()
#define intt long long
const intt mod = 1e9 + 7;
const intt base = 31;
const intt inf = 1e9;
const intt mxN = 500000 + 5;
const intt L = 21;
vector<intt> cnt(mxN);
bool cmp(intt &a, intt &b) {
if(cnt[a] == cnt[b]) return a < b;
return cnt[a] < cnt[b];
}
void solve() {
intt n, m;
cin >> n >> m;
bool is = false;
if(n > m) {
swap(n,m); is = true;
}
intt ans = 0;
vector<vector<char>> g(n + 1, vector<char>(m + 1, '-'));
for(intt i = 1; i <= n; i++) {
vector<intt> jler;
intt fort = 0;
for(intt j = 1; j <= m; j++) {
if((cnt[j] + 1) * 2 >= n) continue;
jler.pb(j);
fort++;
}
if(fort * 2 > m) {
sort(ALL(jler), cmp);
// cout << i << ": ";
// for(intt j : jler) cout << j << " ";
// cout << endl;
for(intt j = 0; j < jler.size(); j++) {
intt curj = jler[j];
cnt[curj]++;
g[i][curj] = '+';
if((j + 1) * 2 > m) break;
}
ans++;
} else {
break;
}
// for(intt j = 1; j <= n; j++) {
// for(intt k = 1; k <= m; k++) {
// cout << g[j][k];
// }
// cout << endl;
// }
}
cout << ans + m << endl;
for(intt i = 1; i <= n; i++) {
for(intt j = 1; j <= m; j++) {
if(is) {
cout << (g[i][j] == '+' ? '-' : '+');
} else {
cout << g[i][j];
}
}
cout << endl;
}
}
signed main() {
SPEED;
intt tst = 1;
cin >> tst;
while (tst--) {
solve();
}
}
# | 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... |