#include <bits/stdc++.h>
using namespace std;
const int NN = 1005;
int a[NN][NN],y[NN],x[NN],f[NN],ans,n,m,b[NN][NN];
void solve(int n,int m){
ans = 0;
int N = n - n/2 - 1,P = 0;
for (int p = 0; p <= m; p++){
int k = m/2 + 1 - p,ig = 0;
if (k>0) ig = min(n, ((m - p)/k)*N);
else ig = n;
if (ans < m - p + ig){
P = p;
ans = m - p + ig;
}
}
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 = 1; j <= P; j++)
a[i][j] = 1;
int k = m/2 + 1 - P;
for (int j = 1; j <= P; j++) y[j] = 0;
for (int j = P+1; j <= m; j++) y[j] = N;
for (int i = 1; i <= n; i++){
int cnt = 0;
for (int j = 1; j <= m; j++) f[j] = 0;
for (int j = 1; j <= m; j++){
if (y[j]) {
--y[j];
f[j] = 1;
cnt++;
}
if (cnt == k) break;
}
if (cnt < k) break;
for (int j = 1; j <= m; j++)
if (f[j]) a[i][j] = 1;
}
}
void rotate(){
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
b[i][j] = a[i][j];
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
a[i][j] = b[j][i];
if (a[i][j]) a[i][j] = 0;
else a[i][j] = 1;
}
}
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int T;
cin>>T;
while (T--){
cin>>n>>m;
if (m < n) solve(m,n),rotate();
else solve(n,m);
cout<<ans<<endl;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (a[i][j]) cout<<"+";
else cout<<"-";
}
cout<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Incorrect |
4 ms |
596 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2052 KB |
Output is correct |
2 |
Correct |
21 ms |
5460 KB |
Output is correct |
3 |
Correct |
23 ms |
7908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1792 KB |
Output is correct |
2 |
Correct |
19 ms |
3920 KB |
Output is correct |
3 |
Correct |
18 ms |
3256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Incorrect |
4 ms |
596 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |