#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
int main() {
ll N;
cin >> N;
while(N--) {
ll n,m;
cin >> n >> m;
pl ha = {0,0},va = {0,0};
for(int i=0;i<(m/2+1);i++) {
ll tot = (m-(m/2+1))*(n-i);
ll ro = (n/2+1)-i;
ll su = 0;
if(ro <= 0) {
su = m;
} else {
su = min(tot/ro,m);
}
if(su+n-i > ha.second) {
ha = {i,su+n-i};
}
}
for(int i=0;i<(n/2+1);i++) {
ll tot = (n-(n/2+1))*(m-i);
ll ro = (m/2+1)-i;
ll su = 0;
if(ro <= 0) {
su = n;
} else {
su = min(tot/ro,n);
}
if(su+m-i > ha.second) {
ha = {i,su+m-i};
}
}
vector<vector<ll> > res;
ll ans = max(ha.second,va.second);
if(ha.second > va.second) {
res.assign(n,vector<ll>(m,1));
ll st = ha.first;
for(int i=0;i<st;i++) {
for(int j=0;j<m;j++) {
res[i][j] = 0;
}
}
ll ro = (n/2+1)-st;
ll rot = ro*(ha.second+st-n);
for(int i=0;i<rot;i++) {
res[(i%(n-st))+st][i/ro] = 0;
}
} else {
res.assign(n,vector<ll>(m,0));
ll st = va.first;
for(int i=0;i<n;i++) {
for(int j=0;j<st;j++) {
res[i][j] = 1;
}
}
ll ro = (m/2+1)-st;
ll rot = ro*(va.second+st-m);
for(int i=0;i<rot;i++) {
res[i/ro][(i%(m-st))+st] = 1;
}
}
cout << ans << '\n';
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
cout << (res[i][j]?'+':'-');
}
cout << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
1600 KB |
Output is correct |
2 |
Correct |
55 ms |
6252 KB |
Output is correct |
3 |
Correct |
45 ms |
6948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
1748 KB |
Output is correct |
2 |
Correct |
44 ms |
5084 KB |
Output is correct |
3 |
Correct |
40 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
5 |
Correct |
54 ms |
1600 KB |
Output is correct |
6 |
Correct |
55 ms |
6252 KB |
Output is correct |
7 |
Correct |
45 ms |
6948 KB |
Output is correct |
8 |
Correct |
50 ms |
1748 KB |
Output is correct |
9 |
Correct |
44 ms |
5084 KB |
Output is correct |
10 |
Correct |
40 ms |
3584 KB |
Output is correct |
11 |
Correct |
18 ms |
620 KB |
Output is correct |
12 |
Correct |
40 ms |
4460 KB |
Output is correct |
13 |
Correct |
43 ms |
3388 KB |
Output is correct |
14 |
Correct |
31 ms |
2540 KB |
Output is correct |
15 |
Correct |
53 ms |
9196 KB |
Output is correct |
16 |
Correct |
40 ms |
6840 KB |
Output is correct |
17 |
Correct |
18 ms |
3180 KB |
Output is correct |