# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N = 1005;
int t,n,m,a[N][N],ans,rem,cur[N],canrow,val,val1,all;
signed main() {
cin>>t;
while (t--) {
cin>>n>>m;
ans = max(n,m);
for (int i = 1; i <= n; i++) {
all = i*((m+2)/2);
canrow = min(n - (n+2)/2, i);
for (int j = 0; j < m; j++) {
if ((m-j)*canrow >= all) {
if (i + (m - j) > ans) {
val = i;
val1 = j;
}
ans = max(ans,i + (m - j));
}
all -= i;
}
}
cout<<ans<<endl;
//cout<<val<<" "<<val1<<endl;
if (ans == m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <=m ;j++) {
cout<<"-";
}
cout<<"\n";
}
continue;
}
if (ans == n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout<<"+";
}
cout<<"\n";
}
continue;
}
for (int i = 1; i <= val; i++) {
canrow = min(n-(n+2)/2,i);
for (int j = 1; j <= val1; j++) {
a[i][j] = 1;
}
rem = (m+2)/2-val1;
// if (i == 1) cout<<rem<<endl;
vector < pair <int, int > > v;
v.clear();
for (int j = val1 + 1; j <= m; j++) {
v.pb({cur[j],j});
}
sort(v.begin(),v.end());
for (int j = 0; j < rem; j++) {
a[i][v[j].s] = 1;
cur[v[j].s]++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {cur[j] = 0;
if (a[i][j] == 1) cout<<"+";
else cout<<"-";
a[i][j] = 0;
}
cout<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
1672 KB |
Output is correct |
2 |
Correct |
59 ms |
4104 KB |
Output is correct |
3 |
Correct |
53 ms |
4776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
1748 KB |
Output is correct |
2 |
Correct |
55 ms |
3840 KB |
Output is correct |
3 |
Correct |
57 ms |
3352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
564 KB |
Output is correct |
5 |
Correct |
62 ms |
1672 KB |
Output is correct |
6 |
Correct |
59 ms |
4104 KB |
Output is correct |
7 |
Correct |
53 ms |
4776 KB |
Output is correct |
8 |
Correct |
60 ms |
1748 KB |
Output is correct |
9 |
Correct |
55 ms |
3840 KB |
Output is correct |
10 |
Correct |
57 ms |
3352 KB |
Output is correct |
11 |
Correct |
14 ms |
552 KB |
Output is correct |
12 |
Correct |
45 ms |
4156 KB |
Output is correct |
13 |
Correct |
50 ms |
4592 KB |
Output is correct |
14 |
Correct |
40 ms |
3812 KB |
Output is correct |
15 |
Correct |
67 ms |
5168 KB |
Output is correct |
16 |
Correct |
50 ms |
4164 KB |
Output is correct |
17 |
Correct |
20 ms |
3268 KB |
Output is correct |