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 <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t;
while (t--) {
int n, m; cin >> n >> m;
bool flip = 0;
if (n > m) {
swap(n, m);
flip = 1;
}
vector<int> cnt(m), ord(m); iota(ord.begin(), ord.end(), 0);
int cut = (n - 1) / 2, need = m / 2 + 1;
int x = m * cut / need;
cout << m + x << "\n";
vector a(n, vector<char>(m, '-'));
for (int i = 0; i < x; ++i) {
sort(ord.begin(), ord.end(), [&](int a, int b) {
return cnt[a] < cnt[b];
});
for (int j = 0; j < need; ++j) {
a[i][ord[j]] = '+';
++cnt[ord[j]];
}
}
if (flip) {
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
cout << char(a[j][i] ^ '+' ^ '-');
}
cout << "\n";
}
} else {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cout << a[i][j];
}
cout << "\n";
}
}
}
return 0;
}
# | 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... |