#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int N = 2005;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
int n,m;
char a[N][N];
int check(int cnt) {
if (2 * cnt < m)
return cnt + n;
int x = (m / 2 + 1) - (m - cnt);
int lef = (n - 1) >> 1;
for (int i = n; i >= 0; i--)
if ((x * i + cnt - 1) / cnt <= lef)
return i + cnt;
assert(false);
return -1;
}
void trace(int r, int c) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
a[i][j] = 0;
for (int i = 1; i <= n; i++)
for (int j = c + 1; j <= m; j++)
a[i][j] = '+';
int x = (m / 2 + 1) - (m - c);
if (x <= 0) {
for (int j = 1; j <= c; j++)
for (int i = 1; i <= n; i++)
a[i][j] = (i <= n / 2 + 1) ? '-' : '+';
return;
}
for (int i = 1, cur = 1; i <= r; i++) {
for (int t = 1; t <= x; t++) {
a[i][cur] = '+';
cur++;
if (cur > c)
cur = 1;
}
for (int j = 1; j <= c; j++)
if (!a[i][j])
a[i][j] = '-';
}
for (int j = 1; j <= c; j++) {
int cnt = (n / 2 + 1);
for (int i = 1; i <= r; i++)
cnt -= a[i][j] == '-';
for (int i = r + 1; i <= n; i++) {
if (cnt > 0) {
a[i][j] = '-';
cnt--;
} else
a[i][j] = '+';
}
}
}
void solve() {
cin >> n >> m;
int ans = 0;
int res = 0;
for (int i = 1; i <= m; i++)
if (maxi(ans, check(i)))
res = i;
cout << ans << "\n";
trace(ans - res, res);
for (int i = 1; i <= n; i++, cout << "\n")
for (int j = 1; j <= m; j++)
cout << a[i][j];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef ONLINE_JUDGE
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
#endif
int t; cin >> t;
while (t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Wrong answer in test 2 1: 1 < 2 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Wrong answer in test 2 1: 1 < 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Wrong answer in test 2 1: 1 < 2 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
1520 KB |
Wrong answer in test 87 1: 44 < 87 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1512 KB |
Output is correct |
2 |
Correct |
38 ms |
2564 KB |
Output is correct |
3 |
Correct |
27 ms |
2172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Wrong answer in test 2 1: 1 < 2 |
3 |
Halted |
0 ms |
0 KB |
- |