#include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
//#define int int64_t
using namespace std;
const int N = int(1e3) + 7;
const int inf = 1e9 + 1;
typedef pair<ll, ll> pii;
int cnt[N], n, m, nr, nc, r, c, res;
void solve() {
cin >> n >> m;
res = m, r = 0, c = m;
nr = m / 2 + 1, nc = n / 2 + 1;
for(int l, h, mid, i = 1; i <= n; ++i) {
l = 0, h = m;
while(l <= h) {
mid = l + h >> 1;
int x = min(mid, m - nr);
int tmp = x * (n - nc);
if(nr - m + mid <= 0) l = mid + 1;
else if(tmp / (nr - m + mid) + (n - nc) >= i) l = mid + 1;
else h = mid - 1;
}
if(i + h > res) res = i + h, r = i, c = h;
}
cout << res << '\n';
vector<vector<char>> ans(n, vector<char>(m, '+'));
for(int i = 0; i < c; ++i) {
for(int j = 0; j < nc; ++j)
ans[j][i] = '-';
}
int tmp = min(c, m - nr) * (n - nc);
if(nr - m + c > 0) {
int x = n - 1, y = 0;
auto nxt = [&](int& x, int& y) {
if(y >= c) --x;
else ++y;
};
for(int i = 0; i < nc; ++i) {
if(tmp < nr - m + c) break;
for(int j = 0; j < nr - m + c; ++j) {
swap(ans[x][y], ans[i][j]);
--tmp;
nxt(x, y);
}
}
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) cout << ans[i][j];
cout << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
int T; cin >> T;
while(T --) solve();
}
Compilation message
stones.cpp: In function 'void solve()':
stones.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid = l + h >> 1;
~~^~~
stones.cpp: In function 'int32_t main()':
stones.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(Task".inp", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(Task".out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 28 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 28 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
in the table A+B is not equal to 28 |