#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, m;
int calc(vector<vector<int>>& a) {
int cur = 0;
for (int i = 0; i < n; ++i) {
int x = 0;
for (int j = 0; j < m; ++j) {
if (a[i][j]) x++;
else x--;
}
if (x > 0) cur++;
}
for (int j = 0; j < m; ++j) {
int x = 0;
for (int i = 0; i < n; ++i) {
if (a[i][j]) x++;
else x--;
}
if (x < 0) cur++;
}
return cur;
}
int main() {
int tt;
cin >> tt;
while (tt--) {
cin >> n >> m;
if (n == 1) {
cout << m << '\n';
for (int i = 0; i < m; ++i) {
cout << "-";
}
cout << '\n';
continue;
}
if (m == 1) {
cout << n << '\n';
for (int i = 0; i < n; ++i) {
cout << "+\n";
}
cout << '\n';
continue;
}
// cout << (n + m - 2 - (1 - n % 2) - (1 - m % 2)) << '\n';
int l;
if (m % 2 == 0) l = (m + 2) / 2;
else l = (m + 1) / 2;
int it = 0;
vector<vector<int>> ans(n, vector<int>(m));
vector<int> cnt(m);
for (int i = 0; i < n; ++i) {
int max1 = 0;
for (int j = 0; j < m; ++j) {
max1 = max(max1, cnt[j]);
}
if (n % 2 == 1) {
if (max1 >= (n - 1) / 2) break;
}
else if (max1 >= (n-2) / 2) break;
for (int j = 0; j < l; ++j) {
ans[i][it] = 1;
cnt[it]++;
it = (it + 1) % m;
}
max1 = 0;
for (int j = 0; j < m; ++j) {
max1 = max(max1, cnt[j]);
}
if (n % 2 == 1) {
if (max1 >= (n - 1) / 2) break;
}
else if (max1 >= (n-2) / 2) break;
}
cout << calc(ans) << '\n';
for (auto e : ans) {
for (auto u : e) {
if (u) cout << "+";
else cout << "-";
}
cout << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Wrong answer in test 4 3: 4 < 5 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Wrong answer in test 20 2: 11 < 20 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Wrong answer in test 4 3: 4 < 5 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
1388 KB |
Wrong answer in test 97 21: 111 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
1644 KB |
Wrong answer in test 24 24: 43 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Wrong answer in test 4 3: 4 < 5 |