#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(){
ans = 0;
int ans1=0,ans2=0;
// if (m >= n){
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++)
b[i][j] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= P; j++)
b[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]) b[i][j] = 1;
}
ans1 = ans;
// }
ans=0;
N = m - m/2 - 1,P = 0;
for (int p = 0; p <= n; p++){
int k = n/2 + 1 - p,ig = 0;
if (k>0) ig = min(m, ((n - p)/k)*N);
else ig = m;
if (ans < n - p + ig){
P = p;
ans = n - p + ig;
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
a[i][j] = 1;
for (int i = 1; i <= P; i++)
for (int j = 1; j <= m; j++)
a[i][j] = 0;
k = n/2 + 1 - P;
for (int i = 1; i <= P; i++) x[i] = 0;
for (int i = P+1; i <= n; i++) x[i] = N;
for (int j = 1; j <= m; j++){
int cnt=0;
for (int i = 1; i <= n; i++) f[i] = 0;
for (int i = 1; i <= n; i++){
if (x[i]){
--x[i];
f[i] = 1;
++cnt;
}
if (cnt == k) break;
}
if (cnt < k) break;
for (int i = 1; i <= n; i++)
if (f[i]) a[i][j] = 0;
}
ans2 = ans;
if (ans1 > ans2){
ans = ans1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
a[i][j] = b[i][j];
}else{
ans = ans2;
}
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int T;
cin>>T;
while (T--){
cin>>n>>m;
solve();
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";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
2084 KB |
Output is correct |
2 |
Correct |
23 ms |
7140 KB |
Output is correct |
3 |
Correct |
22 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2436 KB |
Output is correct |
2 |
Correct |
22 ms |
6748 KB |
Output is correct |
3 |
Correct |
19 ms |
5512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
42 ms |
2084 KB |
Output is correct |
6 |
Correct |
23 ms |
7140 KB |
Output is correct |
7 |
Correct |
22 ms |
8532 KB |
Output is correct |
8 |
Correct |
25 ms |
2436 KB |
Output is correct |
9 |
Correct |
22 ms |
6748 KB |
Output is correct |
10 |
Correct |
19 ms |
5512 KB |
Output is correct |
11 |
Incorrect |
9 ms |
788 KB |
Wrong answer in test 26 8: 30 < 31 |
12 |
Halted |
0 ms |
0 KB |
- |