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;
using ll = long long;
#define ff first
#define ss second
#define pii pair<int, int>
#define all(v) (v).begin(), (v).end()
void solve() {
int n, m;
cin >> n >> m;
int ans = max(n, m);
vector<vector<char>> a;
if (n < m) {
a.assign(n, vector<char>(m, '-'));
vector<int> vis(m);
for (int i = 0; i < n; i++) {
vector<pii> v;
for (int j = 0; j < m; j++)
v.push_back({vis[j], j});
sort(v.begin(), v.end());
bool tr = true;
for (int j = 0; j < (m >> 1) + 1; j++) {
if (v[j].ff == (n - 1 >> 1)) {
tr = false; break;
}
vis[v[j].ss]++;
a[i][v[j].ss] = '+';
}
if (!tr) break;
ans++;
}
}
else {
a.assign(n, vector<char>(m, '+'));
vector<int> vis(n);
for (int i = 0; i < m; i++) {
vector<pii> v;
for (int j = 0; j < n; j++)
v.push_back({vis[j], j});
sort(v.begin(), v.end());
bool tr = true;
for (int j = 0; j < (n >> 1) + 1; j++) {
if (v[j].ff == (m - 1 >> 1)) {
tr = false; break;
}
vis[v[j].ss]++;
a[v[j].ss][i] = '-';
}
if (!tr) break;
ans++;
}
}
cout << ans << '\n';
for (auto i : a) {
for (auto j : i)
cout << j;
cout << '\n';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int T;
cin >> T;
while (T--) solve();
}
Compilation message (stderr)
stones.cpp: In function 'void solve()':
stones.cpp:33:23: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
33 | if (v[j].ff == (n - 1 >> 1)) {
| ~~^~~
stones.cpp:59:23: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
59 | if (v[j].ff == (m - 1 >> 1)) {
| ~~^~~
# | 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... |