#pragma GCC optimize("O3", "unroll-loops") // "Ofast"
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include <bits/stdc++.h>
#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;
using vc = vt<char>;
using vvc = vt<vc>;
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60);
const double eps = 1e-6;
int n, m;
void solve_odd (vvc a) {
cout << n - 1 + m - 1 << '\n';
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
if ((i + j) & 1) a[i][j] = '-';
}
}
for (int j = 1; j <= m; j++) a[n][j] = '-';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) cout << a[i][j];
cout << '\n';
}
}
void solve_m1 (vvc a) {
cout << n << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) cout << a[i][j];
cout << '\n';
}
}
void solve_n1 (vvc a) {
cout << m << '\n';
for (int j = 1; j <= m; j++) a[1][j] = '-';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) cout << a[i][j];
cout << '\n';
}
}
void solve_1_2 (vvc a) {
if (n < m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) a[i][j] = (i > n / 2 + 1 ? '+' : '-');
}
}
else {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) a[i][j] = (j > m / 2 + 1 ? '-' : '+');
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int j = 1; j <= m; j++) cnt += (a[i][j] == '+');
if (cnt > m / 2) ans++;
}
for (int i = 1; i <= m; i++) {
int cnt = 0;
for (int j = 1; j <= n; j++) cnt += (a[j][i] == '-');
if (cnt > n / 2) ans++;
}
cout << ans << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) cout << a[i][j];
cout << '\n';
}
}
void solve () {
cin >> n >> m;
vvc a(n + 1, vc (m + 1, '+'));
if (m == 1) return (void)(solve_m1(a));
if (n == 1) return (void)(solve_n1(a));
bool sub_1_2 = (min(n, m) <= 4), sub4 = ((n & 1) && (m & 1));
if (sub_1_2) {
solve_1_2(a);
return;
}
if (sub4) {
solve_odd(a);
return;
}
cout << '\n';
}
bool testcases = 1;
signed main() {
#ifdef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
cin.tie(0) -> sync_with_stdio(0);
int test = 1;
if (testcases) cin >> test;
for (int cs = 1; cs <= test; cs++) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
4 ms |
292 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1316 KB |
Output is correct |
2 |
Correct |
21 ms |
2236 KB |
Output is correct |
3 |
Correct |
19 ms |
2628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
804 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
4 ms |
292 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |