#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e3 + 5;
signed main(){
fastio;
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
if(n <= m / 2){
vector<vector<char>> arr(n, vector<char>(m, '-'));
cout << m << '\n';
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << arr[i][j];
}
cout << '\n';
}
continue;
}
if(n / 2 >= m){
vector<vector<char>> arr(n, vector<char>(m, '+'));
cout << n << '\n';
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << arr[i][j];
}
cout << '\n';
}
continue;
}
if(n <= m){
vector<vector<char>> arr(n, vector<char>(m, '-'));
vector<pair<int, int>> setirler(n, {m, 0}); // - lerin sayi, + lerin sayi
vector<pair<int, int>> sutunlar(m, {n, 0});
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(setirler[i].first >= setirler[i].second && sutunlar[j].first - 1 > sutunlar[j].second){
arr[i][j] = '+';
setirler[i].first--;
setirler[i].second++;
sutunlar[j].first--;
sutunlar[j].second++;
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
if(setirler[i].first < setirler[i].second){
ans++;
}
}
for(int j = 0; j < m; j++){
if(sutunlar[j].first > sutunlar[j].second){
ans++;
}
}
cout << ans << '\n';
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << arr[i][j];
}
cout << '\n';
}
}else{
vector<vector<char>> arr(n, vector<char>(m, '+'));
vector<pair<int, int>> setirler(n, {0, m}); // - lerin sayi, + lerin sayi
vector<pair<int, int>> sutunlar(m, {0, n});
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(sutunlar[j].first >= sutunlar[j].second && setirler[i].second - 1 > setirler[i].first){
arr[i][j] = '-';
setirler[i].second--;
setirler[i].first++;
sutunlar[j].second--;
sutunlar[j].first++;
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
if(setirler[i].second > setirler[i].first){
ans++;
}
}
for(int j = 0; j < m; j++){
if(sutunlar[j].first > sutunlar[j].second){
ans++;
}
}
cout << ans << '\n';
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << arr[i][j];
}
cout << '\n';
}
}
}
}
//atilla
# | 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... |