#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
char w[1002][1002];
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--) {
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++)
for (int j = 0; j < m; j++)
w[i][j] = '.';
if (n % 2 && m % 2) {
cout << n + m - 2 << '\n';
Nvnvik(n - 1, m - 1, n / 2);
for (int j = 0; j < m; j++)
w[n - 1][j] = '-';
for (int i = 0; i < n - 1; i++)
w[i][m - 1] = '+';
}
if (n % 2 == 0 && m % 2 == 1) {
if (m - 1 - n / 2 <= 1) {
cout << n + m - 2 << '\n';
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 - 3 << '\n';
Nvnvik(n - 2, m - 1, n / 2 - 1);
for (int j = 0; j < m; j++) {
w[n - 1][j] = '-';
w[n - 2][j] = '-';
}
for (int i = 0; i < n; i++) {
w[i][m - 1] = ('+');
}
}
}
if (n % 2 == 1 && m % 2 == 0) {
if (n - 1 - m / 2 <= 1) {
cout << n + m - 2 << '\n';
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 - 3 << '\n';
Nvnvik(n - 1, m - 2, n / 2);
for (int j = 0; j < m; j++) {
w[n - 1][j] = '-';
}
for (int i = 0; i < n; i++) {
w[i][m - 1] = '+';
w[i][m - 2] = '+';
}
}
}
if (n % 2 == 0 && m % 2 == 0) {
if (n - 3 <= m / 2) {
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] = '-';
}
else if (m - 3 <= n / 2) {
cout << n + m - 3 << '\n';
Nvnvik2(n, m - 3, m / 2 - 2);
for (int i = 0; i < n; i++)
w[i][m - 1] = w[i][m - 2] = w[i][m - 3] = '+';
}
else {
cout << n + m - 4 << '\n';
Nvnvik(n - 2, m - 2, n / 2 - 1);
for (int i = 0; i < m; i++)
w[n - 1][i] = w[n - 2][i] = '-';
for (int i = 0; i < n - 2; i++)
w[i][m - 1] = w[i][m - 2] = '+';
}
}
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 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
364 KB |
Output is correct |
4 |
Incorrect |
4 ms |
364 KB |
in the table A+B is not equal to 41 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
1436 KB |
Output is correct |
2 |
Correct |
39 ms |
2028 KB |
Output is correct |
3 |
Correct |
37 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1516 KB |
Output is correct |
2 |
Correct |
36 ms |
1900 KB |
Output is correct |
3 |
Correct |
34 ms |
1644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
364 KB |
Output is correct |
4 |
Incorrect |
4 ms |
364 KB |
in the table A+B is not equal to 41 |