#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int Value(const vector<string>& a)
{
int n = a.size();
int m = a[0].length();
int res = 0;
for (int i = 0; i < n; ++i)
if (2 * count(a[i].begin(), a[i].end(), '+') > m)
++res;
for (int j = 0; j < m; ++j)
{
int cnt = 0;
for (int i = 0; i < n; ++i)
if (a[i][j] == '-')
++cnt;
if (2 * cnt > n)
++res;
}
return res;
}
bool Solve(int n, int nx, int m, int mx)
{
if (nx < 0 || mx < 0 || nx > n || mx > m) return false;
vector<string> a(n, string(m, '-'));
for (int i = n - nx; i < n; ++i)
for (int j = 0; j < m; ++j)
a[i][j] = '-';
for (int i = 0; i < n; ++i)
for (int j = m - mx; j < m; ++j)
a[i][j] = '+';
int block = ((m + 2) / 2 - mx);
int j = m - mx - 1;
if (mx < m)
for (int i = 0; i < n - nx; ++i)
{
for (int cnt = 0; cnt < block; ++cnt)
a[i][(j - cnt + m - mx) % (m - mx)] = '+';
j = (j - block + m - mx) % (m - mx);
}
int value = Value(a);
if (value < n + m - nx - mx)
return false;
cout << value << '\n';
for (int i = 0; i < n; ++i)
cout << a[i] << '\n';
cout << flush;
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
bool printed = false;
for (int sum = 0; !printed && sum <= 4; ++sum)
for (int i = 0; !printed && i <= 2; ++i)
if (Solve(n, i, m, sum - i))
{
printed = true;
break;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Incorrect |
7 ms |
376 KB |
Wrong answer in test 4 26: 26 < 27 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1400 KB |
Output is correct |
2 |
Correct |
31 ms |
1780 KB |
Output is correct |
3 |
Correct |
25 ms |
1936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1404 KB |
Output is correct |
2 |
Correct |
31 ms |
1572 KB |
Output is correct |
3 |
Correct |
30 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Incorrect |
7 ms |
376 KB |
Wrong answer in test 4 26: 26 < 27 |