#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int inf = 2e18,N = 5e5+1,MOD = 1e9+7;
void solve() {
/*
-++-+
+-++-
++-+-
//2 2 2
//
-----
-----
*/
int ans = 0;
int n,m;
cin >> n >> m;
int R = 0;
for (int r = 0;r <= n;r++) {
//r tanesinde m/2+1 tane + olcak
int need = max(0ll,n/2+1-(n-r));
int have = r*(m-(m/2+1));
if ((need?(r+have/need):(m)) > ans) {
ans = (need?(r+have/need):(m));
R = r;
}
}
cout << ans << endl;
int r = R;
if (!r) {
for (int i = 0;i<n;i++) {
for (int j = 0;j<m;j++) cout << '-';
cout << '\n';
}
return;
}
vector<vector<char>> brd(n,vector<char>(m,'-'));
for (int i = 0;i<r;i++) {
for (int j = 0;j<m;j++) brd[i][j] = '+';
}
int need = max(0ll,n/2+1-(n-r));
vi got(r,(m-(m/2+1)));
int ptr = 0;
int col = -1;
cout << need << '\n';
while (col < m) {
++col;
bool fl = 1;
for (int j = ptr,ctr = 0;ctr < need;ctr++,j = (j+1)%r) {
fl&=got[j];
}
if (!fl) break;
for (int j = ptr,ctr = 0;ctr < need;ctr++,j = (j+1)%r) {
brd[j][col] = '-';
got[j]--;
}
ptr = (ptr+need)%r;
}
for (int i = 0;i<r;i++) {
int ptr = m-1;
while (got[i]--) {
brd[i][ptr] = '-';
}
}
for (int i = 0;i<n;i++) {
for (int j = 0;j<m;j++) cout << brd[i][j] << ' ';
cout << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
cin >> t;
while (t --> 0) 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... |