#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define Sz(x) (int)x.size()
#define mp make_pair
typedef long long ll;
const int N = 1005;
int n, m;
char a[N][N];
int calc() {
int res = 0;
for (int i = 1; i <= n; i++) {
int blue = 0, red = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == '-') blue++;
else red++;
}
if (red > blue) res++;
}
for (int j = 1; j <= m; j++) {
int blue = 0, red = 0;
for (int i = 1; i <= n; i++) {
if (a[i][j] == '-') blue++;
else red++;
}
if (blue > red) res++;
}
return res;
}
void solve() {
cin >> n >> m;
if (min(n, m) == 1) {
if (n == 1) {
for (int j = 1; j <= m; j++) {
a[1][j] = '-';
}
}
else {
for (int i = 1; i <= n; i++) {
a[i][1] = '+';
}
}
}
else if (min(n, m) == 2) {
if (n == 2) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '-';
}
}
}
else {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '+';
}
}
}
}
else if (min(n,m) == 3) {
if (n == 3) {
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '-';
}
}
for (int j = 1; j <= m; j++) {
a[3][j] = '+';
}
}
else {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2; j++) {
a[i][j] = '+';
}
}
for (int i = 1; i <= n; i++) {
a[i][3] = '-';
}
}
}
else {
if (n == 4) {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '-';
}
}
for (int j = 1; j <= m; j++) {
a[4][j] = '+';
}
}
else {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3; j++) {
a[i][j] = '+';
}
}
for (int i = 1; i <= n; i++) {
a[i][4] = '-';
}
}
}
cout << calc() << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << a[i][j];
}
cout << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while ( t-- ) {
solve();
//cout << '\n';
}
}
| # | 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... |