#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int gcd(int a, int b)
{
if (b == 0) return a;
return gcd(b, a % b);
}
ll binpow(ll a, ll b)
{
if (b == 0) return 1;
ll res = binpow(a, b / 2);
if (b % 2) return res * res * a;
return res * res;
}
bool isprime(int n) {
if (n == 1 || n == 0) return 0;
for (int i = 2; i * i <= n; i++) if (!(n % i)) return 0;
return 1;
}
void solve() {
int n, m; cin >> n >> m;
int mn = m + n;
//if (n == m && n % 2) {
// cout << mn - 2 << endl;
//}
//else if (n == m && !(n % 2)) {
// cout << mn - 4 << endl;
//}
if (m <= 2 && m < n) {
cout << n << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << '+';
}
cout << endl;
}
return;
}
if (n <= 2) {
cout << m << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << '-';
}
cout << endl;
}
return;
}
if (n <= 4 && m <= 4) {
cout << max(m, n) + 1 << endl;
}
else if ((min(m, n) == 3 || min(m, n) == 4) && !(max(m, n) % 2)) cout << max(m, n) + 1 << endl;
else if ((n % 2) != (m % 2)) cout << mn - 3 << endl;
else {
if (n % 2) cout << mn - 2 << endl;
else cout << mn - 4 << endl;
}
vector<vector<char>> v(n * m);
if ((n == m && (n == 3 || n == 4)) || ((n == 3 || n == 4) && !(m % 2))) {
for (int j = 0; j < m; j++) v[0].push_back('+');
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
v[i].push_back('-');
}
}
}
else if (!(n % 2) && (m == 3 || m == 4)) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m - 1; j++) v[i].push_back('+');
v[i].push_back('-');
}
}
else {
for (int j = 0; j < m; j++) v[0].push_back('-');
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i % 2)){
if (j < (m / 2 + 1)) {
v[i].push_back('+');
}
else v[i].push_back('-');
}
else {
if (j >= (m - m / 2 - 1)) {
v[i].push_back('+');
}
else v[i].push_back('-');
}
}
}
if (!(n % 2)) {
for (int j = 0; j < m; j++) v[n - 1][j] = '-';
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << v[i][j];
}
cout << endl;
}
//
// ++
// ++
//
// ------
// ------
// ------
// ------
// ++++++
// ++++++
// ++++++
//
// -----
// -----
// -----
// +++++
//
//
// ----
// ----
// ++++
//
// +++
// ++-
// ++-
// ++-
//
//
// ++
// ++
// ++
// ++
// ++
// ++
//
// ++-+-+
// +----+
// +-+-++
//
// ++-+-
// +----
// +-+-+
//
// ---
// ++-
// -++
// ++-
// -++
//
// -----
// +++--
// --+++
// -----
//
// ++-
// ++-
// ++-
// +++
//
// ------
// ++++--
// --++++
// ++++--
// --++++
// ------
//
//
// ++++--
// --++++
// ++++--
// --++++
// ------
//
//
//
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t; cin >> t; while(t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
6 ms |
340 KB |
Output is correct |
4 |
Incorrect |
10 ms |
340 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
1568 KB |
Output is correct |
2 |
Correct |
35 ms |
17364 KB |
Output is correct |
3 |
Correct |
35 ms |
19052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
1820 KB |
Wrong answer in test 6 6: 8 < 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
6 ms |
340 KB |
Output is correct |
4 |
Incorrect |
10 ms |
340 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |