This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |