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 all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
void solve() {
int n, m; cin >> n >> m;
if (n == 1) {
cout << m << '\n';
for (int i = 0; i < m; i++) cout << '-';
cout << '\n';
return;
}
if (m == 1) {
cout << n << '\n';
for (int i = 0; i < n; i++) {
cout << "+\n";
}
return;
}
pair<int, int> b = {0, 0};
for (int r = 0; r <= n; r++) {
for (int c = 0; c <= m; c++) {
int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r));
if (needc * c + needr * r <= r * c) {
if (b.first + b.second < r + c) {
b = {r, c};
}
}
}
}
cout << b.first + b.second << '\n';
vector<vector<char>> ans(n, vector<char>(m, '+'));
for (int j = b.second; j < m; j++) {
for (int i = 0; i < n; i++) ans[i][j] = '+';
}
for (int i = b.first; i < n; i++) {
for (int j = 0; j < b.second; j++) ans[i][j] = '-';
}
int r = b.first, c = b.second;
int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r));
int cur = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c - needr; j++) {
ans[i][cur] = '-';
cur = (cur + 1) % c;
}
}
for (auto &u : ans) {
for (auto v : u) cout << v;
cout << '\n';
}
}
signed main() {
int tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
stones.cpp: In function 'void solve()':
stones.cpp:47:46: warning: unused variable 'needc' [-Wunused-variable]
47 | int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r));
| ^~~~~
# | 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... |