#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) {//checked
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) {//checked
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) {//checked
cout << n + m - 2 << '\n';
Nvnvik(n, m - 2, n / 2 + 1);
for (int i = 0; i < n; i++)
w[i][m - 1] = w[i][m - 2] = '+';
}
else {//checked
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) {//checked
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 {//checked
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) {//checked
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) {//checked
cout << n + m - 3 << '\n';
Nvnvik(n, m - 3, n / 2 + 1);
for (int i = 0; i < n; i++)
w[i][m - 1] = w[i][m - 2] = w[i][m - 3] = '+';
}
else {//checked
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
1388 KB |
Output is correct |
2 |
Correct |
41 ms |
2028 KB |
Output is correct |
3 |
Correct |
38 ms |
2156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
1516 KB |
Output is correct |
2 |
Correct |
36 ms |
1900 KB |
Output is correct |
3 |
Correct |
33 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
5 |
Correct |
46 ms |
1388 KB |
Output is correct |
6 |
Correct |
41 ms |
2028 KB |
Output is correct |
7 |
Correct |
38 ms |
2156 KB |
Output is correct |
8 |
Correct |
44 ms |
1516 KB |
Output is correct |
9 |
Correct |
36 ms |
1900 KB |
Output is correct |
10 |
Correct |
33 ms |
1644 KB |
Output is correct |
11 |
Correct |
13 ms |
620 KB |
Output is correct |
12 |
Correct |
34 ms |
1900 KB |
Output is correct |
13 |
Correct |
36 ms |
2028 KB |
Output is correct |
14 |
Correct |
27 ms |
1644 KB |
Output is correct |
15 |
Correct |
50 ms |
2284 KB |
Output is correct |
16 |
Correct |
37 ms |
1900 KB |
Output is correct |
17 |
Correct |
15 ms |
1388 KB |
Output is correct |