This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
int t, n, m, ans, r[N], c[N];
char a[2][N][N];
string b[3];
int f() {
for (int i = 0; i < n; i++) {
r[i] = 0;
}
for (int i = 0; i < m; i++) {
c[i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[1][i][j] == '+') r[i]++;
else c[j]++;
}
}
int y = 0;
for (int i = 0; i < n; i++) {
y += (r[i] > m/2);
}
for (int i = 0; i < m; i++) {
y += (c[i] > n/2);
}
return y;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> t;
while (t--) {
cin >> n >> m;
ans = 0;
b[0].clear();
b[0].resize(n, '+');
for (int i = 0; i <= n/2; i++) {
b[0][i] = '-';
}
b[1].clear();
b[1].resize(n, '+');
for (int i = 0; i <= n/2; i++) {
b[1][n-1-i] = '-';
}
b[2].clear();
b[2].resize(n, '+');
for (int i = 0; i <= n/4; i++) {
b[2][i] = '-';
b[2][n-1-i] = '-';
}
int x = (m-1) / 2 / 2 * 3 + ((m-1)/2 % 2 ? 1 : 0);
for (int i = 0; i <= n; i++) {
for (int j = 0; j < m-x; j++) {
a[1][i][j] = '+';
}
int curr = 0;
for (int j = m-x; j < m; j++) {
a[1][i][j] = b[curr][i];
curr = (curr+1) % 3;
}
}
x = f();
if (x > ans) {
ans = x;
swap(a[0], a[1]);
}
b[0].clear();
b[0].resize(m, '-');
for (int i = 0; i <= m/2; i++) {
b[0][i] = '+';
}
b[1].clear();
b[1].resize(m, '-');
for (int i = 0; i <= m/2; i++) {
b[1][m-1-i] = '+';
}
b[2].clear();
b[2].resize(m, '-');
for (int i = 0; i <= m/4; i++) {
b[2][i] = '+';
b[2][m-1-i] = '+';
}
x = (n-1) / 2 / 2 * 3 + ((n-1)/2 % 2 ? 1 : 0);
for (int j = 0; j <= m; j++) {
for (int i = 0; i < n-x; i++) {
a[1][i][j] = '-';
}
int curr = 0;
for (int i = n-x; i < n; i++) {
a[1][i][j] = b[curr][j];
curr = (curr+1) % 3;
}
}
x = f();
if (x > ans) {
ans = x;
swap(a[0], a[1]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[1][i][j] = '+';
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i <= n/2 && j < m/2) || (i >= n/2 && j > m/2)) a[1][i][j] = '-';
}
}
x = f();
if (x > ans) {
ans = x;
swap(a[0], a[1]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[1][i][j] = '+';
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i < n/2 && j <= m/2) || (i > n/2 && j >= m/2)) a[1][i][j] = '+';
}
}
x = f();
if (x > ans) {
ans = x;
swap(a[0], a[1]);
}
cout << ans << "\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << a[0][i][j];
}
cout << "\n";
}
/*
if (n%2 == 0 && m%2 == 0) {
}
else if (n%2 == 0 && m%2 == 1) {
}
else if (n%2 == 1 && m%2 == 0) {
}
else if (n%2 == 1 && m%2 == 1) {
}
*/
}
}
/*
--++++
++--++
++++--
------
------
--++++
----++
------
++----
++++--
*/
# | 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... |