#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<random>
#include<cmath>
#include<stack>
#include<map>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;
ll pv(ll a, ll b) {
if (b == 0)return 1;
ll res = (pv(a, b / 2));
if (b % 2) {
return (((res * res) % mod) * (a % mod)) % mod;
}
else {
return (res * res) % mod;
}
}
ll gcd(ll a, ll b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
void solve() {
int n, m;
cin >> n >> m;
if(m<=4&&n<=4) {
int mx = 0;
vector<vector<int>>ansik;
for (int p = 0; p < (1 << (n * m)); p++) {
vector<vector<int>>v(n, vector<int>(m));
for (int j = 0; j < n * m; j++) {
if (p & (1 << j)) {
v[j / m][j % m]++;
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = 0; j < m; j++) {
if (v[i][j])cnt++;
else cnt--;
}
if (cnt>=1)ans++;
}
for (int j = 0; j < m; j++) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (v[i][j] == 0)cnt++;
else cnt--;
}
if (cnt>=1)ans++;
}
if (ans > mx) {
mx = ans;
ansik = v;
}
}
cout << mx << endl;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(ansik[i][j]) {
cout<<"+";
}
else cout<<"-";
}
cout<<endl;
}
}
else if(min(n,m)<=4) {
if(n<=2) {
cout<<m<<endl;
for(int i=0; i<n; i++) {
for(int i=0; i<m; i++) {
cout<<'-';
}
cout<<endl;
}
}
else if(m<=2) {
cout<<n<<endl;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
cout<<'+';
}
cout<<endl;
}
}
else if(min(m,n)==3||min(m,n)==4){
if(n<m) {
cout<<m+1<<endl;
for(int i=0; i<n-1; i++) {
for(int i=0; i<m; i++)cout<<'-';
cout<<endl;
}
for(int i=0; i<m; i++)cout<<'+';
cout<<endl;
}
else {
cout<<n+1<<endl;
for(int i=0; i<n; i++) {
if(m==3)cout<<"++-"<<endl;
else if(m==4)cout<<"+++-"<<endl;
}
}
}
}
else {
if(m>=n) {
cout<<m+(n+1)/2<<endl;
for(int i=0; i<n/2; i++) {
for(int j=0; j<m; j++) {
cout<<'-';
}
cout<<endl;
}
int ape=0;
for(int i=0; i<(n)/2; i++) {
for(int j=0;j<ape;j++){
cout<<'-';
}
for(int j=0;j<(m+1)/2;j++){
cout<<'+';
}
for(int j=ape+(m+1)/2; j<m; j++) {
cout<<'-';
}
cout<<endl;
ape++;
}
cout<<'+';
for(int j=0;j<m/2;j++)cout<<'-';
for(int j=0;j<m/2;j++)cout<<'+';
cout<<endl;
}
else {
swap(n,m);
vector<vector<char>>v(n,vector<char>(m));
cout<<m+(n+1)/2<<endl;
for(int i=0; i<n/2; i++) {
for(int j=0; j<m; j++) {
v[i][j]='-';
}
}
int ape=0;
for(int i=n/2; i<n/2+n/2; i++) {
for(int j=0;j<ape;j++){
v[i][j]='-';
}
for(int j=ape;j<ape+(m+1)/2;j++){
v[i][j]='+';
}
for(int j=ape+(m+1)/2; j<m; j++) {
v[i][j]='-';
}
ape++;
}
// cout<<'+';
v[n-1][0]='+';
for(int j=1;j<=m/2;j++)v[n-1][j]='-';
for(int j=m/2+1;j<m;j++)v[n-1][j]='+';
for(int j=0;j<m;j++){
for(int i=0;i<n;i++){
if(v[i][j]=='+')cout<<'-';
else cout<<'+';
}
cout<<endl;
}
cout<<endl;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll _ = 1;
cin >> _;
while (_--) {
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... |