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
#define cerr cout
#else
#define cerr if (false) cout
#endif
void solve() {
int n, m;
cin >> n >> m;
int ra = 0, rb = m;
for (int a = 1; a <= n; a++) {
int l = 0, r = m + 1;
while (r - l > 1) {
int b = (l + r) / 2;
int k = max(0, m / 2 + 1 - m + b);
if ((n - n / 2 - 1) * b >= k * a)
l = b;
else
r = b;
}
if (a + l > ra + rb)
ra = a, rb = l;
}
cerr << ra << ' ' << rb << '\n';
char arr[n][m];
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
arr[i][j] = '-';
for (int i = 0; i < ra; i++)
for (int j = rb; j < m; j++)
arr[i][j] = '+';
int k = max(0, m / 2 + 1 - m + rb);
int l = 0;
for (int i = 0; i < ra; i++) {
for (int j = 0; j < k; j++) {
arr[i][l] = '+';
l = (l + 1) % rb;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
cout << arr[i][j];
cout << '\n';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int number_of_tests;
cin >> number_of_tests;
for (int current_test = 0; current_test < number_of_tests; current_test++) {
cerr << "++++++++++++ #" << current_test << " ++++++++++++++++\n";
solve();
cerr << "++++++++++++++++++++++++++++++++\n\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... |