#include <iostream>
#include <vector>
using namespace std;
bool t1(int n, int m)
{
return max(n, m) <= 4;
}
bool t2(int n, int m)
{
return min(n, m) <= 3;
}
bool t3(int n, int m)
{
return min(n, m) <= 5;
}
void test_case()
{
int n, m;
cin >> n >> m;
if (t1(n, m))
{
int mx = 0;
vector<vector<bool>> ans;
int k = n * m;
for (int i = 0; i < (1 << k); i++)
{
vector<vector<bool>> v(n, vector<bool>(m));
for (int j = 0; j < k; j++)
{
if ((i >> j) & 1)
{
int r = j / m, c = j % m;
v[r][c] = 1;
}
}
int A = 0, B = 0;
for (int j = 0; j < n; j++)
{
int a = 0, b = 0;
for (int k = 0; k < m; k++)
{
if (v[j][k]) a++;
else b++;
}
if (a > b) A++;
}
for (int j = 0; j < m; j++)
{
int a = 0, b = 0;
for (int k = 0; k < n; k++)
{
if (v[k][j]) a++;
else b++;
}
if (b > a) B++;
}
if (A + B > mx) ans = v, mx = A + B;
}
cout << mx << "\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (ans[i][j]) cout << '+';
else cout << '-';
}
cout << "\n";
}
return;
}
if (t2(n, m))
{
if (m >= n)
{
if (n <= 2) cout << m << "\n";
else cout << m + 1 << "\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (i < (n - 1) / 2) cout << '+';
else cout << '-';
}
cout << "\n";
}
}
else
{
if (m <= 2) cout << n << "\n";
else cout << n + 1 << "\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m - 1; j++) cout << '+';
if (m <= 2) cout << "+\n";
else cout << "-\n";
}
}
return;
}
if (t3(n, m))
{
if (min(n, m) == 4)
{
if (m >= n)
{
cout << m + 1 << "\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (i == 0) cout << '+';
else cout << '-';
}
cout << "\n";
}
}
else
{
cout << n + 1 << "\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (j == m - 1) cout << '-';
else cout << '+';
cout << "\n";
}
}
}
}
else
{
if (m >= n)
{
if (m % 2 == 0) cout << m + 2 << "\n";
else cout << m + 3 << "\n";
int cnt = m / 2 + 1;
for (int i = 0; i < cnt; i++) cout << '+';
for (int i = cnt; i < m; i++) cout << '-';
cout << "\n";
cout << '-';
for (int i = 0; i < cnt; i++) cout << '+';
for (int i = cnt + 1; i < m; i++) cout << '-';
cout << "\n";
int r = 2;
if (m & 1)
{
r++;
cout << '+';
for (int i = 1; i < cnt; i++) cout << '-';
for (int i = cnt; i < m; i++) cout << '+';
cout << "\n";
}
for (int i = r; i < n; i++)
{
for (int j = 0; j < m; j++) cout << '-';
cout << "\n";
}
}
else
{
if (n % 2 == 0) cout << n + 2 << "\n";
else cout << n + 3 << "\n";
cout << "-+";
if (n % 2 == 0) cout << '+';
else cout << '-';
cout << "++\n";
int cnt = n / 2 + 1;
for (int i = 1; i < cnt; i++) cout << "--+++\n";
cout << "+-";
if (n % 2 == 0) cout << '+';
else cout << '-';
cout << "++\n";
for (int i = cnt + 1; i < n; i++)
{
if (n % 2 == 0) cout << "+++++\n";
else cout << "++-++\n";
}
}
}
return;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--)
test_case();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
25 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
25 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Incorrect |
54 ms |
436 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
292 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
25 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Incorrect |
54 ms |
436 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |