#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)<=3){
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(n<m){
cout<<m+1<<endl;
for(int i=0;i<m;i++)cout<<'-';
cout<<endl;
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++){
cout<<"++-"<<endl;;
}
}
}
}
else{
if(m>n){
cout<<m+n/2<<endl;
for(int i=0;i<(n+1)/2;i++){
for(int j=0;j<m;j++){
cout<<'-';
}
cout<<endl;
}
for(int i=0;i<n/2;i++){
for(int j=0;j<m;j++){
cout<<'+';
}
cout<<endl;
}
}
else{
cout<<n+m/2<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<(m+1)/2;j++){
cout<<'+';
}
for(int j=0;j<m/2;j++){
cout<<'-';
}
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... |