This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I stand with PALESTINE
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
void out(int n, int m, vector<vector<char>> &a) {
int ans = 0;
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = 0; j < m; j++) cnt += a[i][j] == '+';
ans += cnt > m - cnt;
}
for (int j = 0; j < m; j++) {
int cnt = 0;
for (int i = 0; i < n; i++) cnt += a[i][j] == '-';
ans += cnt > n - cnt;
}
cout << ans << '\n';
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cout << a[i][j];
cout << '\n';
}
}
void solve() {
int n, m;
cin >> n >> m;
if (n >= m) {
vector a(n, vector(m, '+'));
vector<pair<int, int>> b(n);
for (int i = 0; i < n; i++) b[i] = make_pair(m, i);
for (int j = 0; j < m; j++) {
sort(b.rbegin(), b.rend());
int need = n - (n - 1) / 2;
if (b[need - 1].first <= m - (m - 1) / 2) break;
for (int i = 0; i < need; i++) {
a[b[i].second][j] = '-';
b[i].first--;
}
}
out(n, m, a);
} else {
vector a(n, vector(m, '-'));
vector<pair<int, int>> b(m);
for (int j = 0; j < m; j++) b[j] = make_pair(n, j);
for (int i = 0; i < n; i++) {
sort(b.rbegin(), b.rend());
int need = m - (m - 1) / 2;
if (b[need - 1].first <= n - (n - 1) / 2) break;
for (int j = 0; j < need; j++) {
a[i][b[j].second] = '+';
b[j].first--;
}
}
out(n, m, a);
}
}
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q = 1;
cin >> q;
while (q--) {
solve();
// 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... |