#include <bits/stdc++.h>
//#define int long long
#define fr first
#define sc second
#define all(s) s.begin(), s.end()
#define szof(s) (int)s.size()
using namespace std;
const int N = (int)1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = (int)1e9 + 9;
int tests = 1;
int n, m, ans;
bool can(int i, int j) {
return (i >= 1 && i <= n && j >= 1 && j <= m);
}
void solve() {
ans = 0;
cin >> n >> m;
char c[n + 2][m + 2];
vector <int> col(m + 2, 0);
vector <int> row(n + 2, 0);
if (m > n) {
for (int j = 1; j <= m; j++) {
col[j] = n;
}
memset(c, '-', sizeof c);
// want ++-
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (col[j] - 1 > n - (col[j] - 1)) {
int ii = i, jj = j, cnt = 0;
while (can(ii, jj) && row[ii] <= m - row[ii] && (col[jj] - 1 > n - (col[jj] - 1))) {
col[jj]--;
row[ii]++;
c[ii][jj] = '+';
jj++;
cnt++;
}
if (row[ii] <= m - row[ii]) {
jj--;
while (cnt--) {
col[jj]++;
row[ii]--;
c[ii][jj] = '-';
jj--;
}
}
}
}
}
}
else {
for (int i = 1; i <= n; i++) {
row[i] = m;
}
memset(c, '+', sizeof c);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (row[i] - 1 > m - (row[i] - 1)) {
int ii = i, jj = j, cnt = 0;
while (can(ii, jj) && col[jj] <= n - col[jj] && row[ii] - 1 > m - (row[ii] - 1)) {
col[jj]++;
row[ii]--;
c[ii][jj] = '-';
ii++;
cnt++;
}
if (col[jj] <= n - col[jj]) {
ii--;
while (cnt--) {
col[jj]--;
row[ii]++;
c[ii][jj] = '+';
ii--;
}
}
}
}
}
}
for (int i = 1; i <= n; i++) {
if (row[i] > m - row[i]) {
ans++;
}
}
for (int j = 1; j <= m; j++) {
if (col[j] > n - col[j]) {
ans++;
}
}
// cout << "stroki\n";
// for (int i = 1; i <= n; i++) {
// cout << row[i] << " ";
// }
// cout << "\nstolbsi\n";
// for (int i = 1; i <= m; i++) {
// cout << col[i] << " ";
// }cout << endl;
printf("%d\n", ans);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << c[i][j];
}puts("");
}
}
main() {
cin >> tests;
while (tests--) {
solve();
}
}
Compilation message
stones.cpp:121:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Incorrect |
6 ms |
376 KB |
Wrong answer in test 5 29: 31 < 32 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
1312 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
1316 KB |
Wrong answer in test 24 24: 35 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Incorrect |
6 ms |
376 KB |
Wrong answer in test 5 29: 31 < 32 |