#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define sz(s) (int)(s.size())
#define eb emplace_back
#define all(x) x.begin(), x.end()
const int N = 2e6;
const int NN = 4e3;
char a[NN][NN];
int c[N], r[N];
void solve(int n, int m) {
if (n <= m) {
for (int i = 1; i <= n; ++ i) {
r[i] = 0;
for (int j = 1; j <= m; ++ j) {
a[i][j] = '-';
c[j] = 0;
}
}
int need = (m / 2 + 1);
int mx = n - (n / 2 + 1);
int pos = 1;
int ans = 0;
for (int i = 1; i <= n; ++ i) {
int cnt = 0;
int rev = pos;
pos += need;
if (pos > m)
pos -= m;
int res = 0;
while(cnt <= m and r[i] < need) {
if (res == need)
break;
if (c[rev] < mx) {
a[i][rev] = '+';
c[rev]++;
r[i]++;
++res;
}
++rev;
if (rev > m)
rev = 1;
++cnt;
}
if (r[i] == need)
++ans;
if (cnt == m)
if (res != need)
break;
}
cout << m + ans << '\n';
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j)
cout << a[i][j];
cout << '\n';
}
return;
}
else {
for (int j = 1; j <= m; ++ j){
c[j] = 0;
for (int i = 1; i <= n; ++ i){
r[i] = 0;
a[i][j] = '+';
}
}
int need = (n / 2 + 1);
int mx = m - (m / 2 + 1);
int pos = 1;
int ans = 0;
for (int i = 1; i <= m; ++ i) {
int cnt = 0;
int rev = pos;
pos += need;
if (pos > n)
pos -= n;
int res = 0;
while(cnt <= n and c[i] < need) {
if (res == need)
break;
if (r[rev] < mx) {
a[rev][i] = '-';
r[rev]++;
c[i]++;
++res;
}
++rev;
if (rev > n)
rev = 1;
++cnt;
}
if (c[i] == need)
++ans;
if (cnt == n)
if (res != need)
break;
}
cout << n + ans << '\n';
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j)
cout << a[i][j];
cout << '\n';
}
}
}
int main () {
int t;
cin >> t;
while(t--) {
int n, m;
cin >> n >> m;
solve(n, m);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
6 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
1784 KB |
Output is correct |
2 |
Correct |
44 ms |
4216 KB |
Output is correct |
3 |
Correct |
52 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1916 KB |
Output is correct |
2 |
Correct |
39 ms |
4052 KB |
Output is correct |
3 |
Correct |
35 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
6 ms |
632 KB |
Output is correct |
5 |
Correct |
46 ms |
1784 KB |
Output is correct |
6 |
Correct |
44 ms |
4216 KB |
Output is correct |
7 |
Correct |
52 ms |
4984 KB |
Output is correct |
8 |
Correct |
44 ms |
1916 KB |
Output is correct |
9 |
Correct |
39 ms |
4052 KB |
Output is correct |
10 |
Correct |
35 ms |
3320 KB |
Output is correct |
11 |
Correct |
15 ms |
760 KB |
Output is correct |
12 |
Correct |
46 ms |
4216 KB |
Output is correct |
13 |
Correct |
48 ms |
4728 KB |
Output is correct |
14 |
Correct |
34 ms |
4032 KB |
Output is correct |
15 |
Correct |
53 ms |
5284 KB |
Output is correct |
16 |
Correct |
35 ms |
4160 KB |
Output is correct |
17 |
Correct |
21 ms |
3320 KB |
Output is correct |