#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
char w[1002][1002];
vector<char> s[1002];
void KentSolve(int n, int m) {
int a = n - 1;
int b = m - 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (i < a / 2 && j < b / 2)
s[i].push_back('-');
else if (i >= a / 2 && i < a && j >= b / 2 && j < b)
s[i].push_back('-');
else if (i >= a)
s[i].push_back('-');
else if (j >= b)
s[i].push_back('+');
else s[i].push_back('+');
}
}
void Nvnvik(int n, int m, int k) {
int i = 0, j = 0;
while (i < m)
{
int cnt = 0;
while (cnt < k)
{
w[j][i] = '-';
j++;
if (j >= n)
j = 0;
cnt++;
}
i++;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (w[i][j] == '.')
w[i][j] = '+';
}
void Nvnvik2(int n, int m, int k) {
int i = 0, j = 0;
while (i < m)
{
int cnt = 0;
while (cnt < k)
{
w[i][j] = '+';
j++;
if (j >= m)
j = 0;
cnt++;
}
i++;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (w[i][j] == '.')
w[i][j] = '-';
}
int main()
{
int t;
cin >> t;
while (t--)
{
bool ok = true;
int n, m;
cin >> n >> m;
if (min(n, m) <= 2) {
cout << max(m, n) << '\n';
char d;
if (m > n)
d = '-';
else d = '+';
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cout << d;
cout << '\n';
}
continue;
}
for (int i = 0; i <= n; i++)
{
s[i].clear();
for (int j = 0; j < m; j++)
w[i][j] = '.';
}
if (n % 2 && m % 2) {
cout << n + m - 2 << '\n';
KentSolve(n, m);
}
if (n % 2 == 0 && m % 2 == 1) {
if (n - m / 2 <= 1) {
ok = false;
Nvnvik2(n, m - 2, m / 2 - 1);
for (int i = 0; i < n; i++)
w[i][m - 1] = w[i][m - 2] = '-';
}
else {
cout << n + m - 2 << '\n';
KentSolve(n - 1, m - 2);
for (int j = 0; j < m; j++)
s[n - 1].push_back('-');
for (int i = 0; i < n - 1; i++) {
s[i].push_back('+');
s[i].push_back('+');
}
}
}
if (n % 2 == 1 && m % 2 == 0) {
if (m - n / 2 <= 1) {
ok = false;
Nvnvik(n - 2, m, n / 2 - 1);
for (int i = 0; i < m; i++)
w[n - 1][i] = w[n - 2][i] = '-';
}
else {
cout << n + m - 2 << '\n';
KentSolve(n - 2, m - 1);
for (int j = 0; j < m; j++) {
s[n - 2].push_back('-');
s[n - 1].push_back('-');
}
for (int i = 0; i < n - 2; i++)
s[i].push_back('+');
}
}
if (n % 2 == 0 && m % 2 == 0) {
ok = false;
cout << n + m - 3 << '\n';
Nvnvik(n - 3, m, n / 2 - 2);
for (int i = 0; i < m; i++)
w[n - 1][i] = w[n - 2][i] = w[n - 3][i] = '-';
}
if (ok) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
cout << s[i][j];
cout << '\n';
}
}
else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
cout << w[i][j];
cout << '\n';
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 5 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
in the table A+B is not equal to 5 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 5 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1536 KB |
Output is correct |
2 |
Correct |
43 ms |
2796 KB |
Output is correct |
3 |
Correct |
47 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
1516 KB |
in the table A+B is not equal to 45 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 5 |