#include <bits/stdc++.h>
using namespace std;
int t, n, m, k, b[4], fp;
bitset<4> s[4], fps[4];
void G(int ii) {
if(ii == n) {
int tp = 0;
for(int i = 0; i < n; ++i) {
int x = 0;
for(int j = 0; j < m; ++j) {
if(s[i][j]) ++x;
}
if(x > m - x) ++tp;
}
for(int i = 0; i < m; ++i) {
int x = 0;
for(int j = 0; j < n; ++j) {
if(!s[j][i]) ++x;
}
if(x > n - x) ++tp;
}
if(tp > fp) {
fp = tp;
for(int i = 0; i < n; ++i) {
fps[i] = s[i];
}
}
return;
}
for(b[ii] = 0; b[ii] < k; ++b[ii]) {
s[ii] = b[ii];
G(ii + 1);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> t;
for(int ti = 1; ti <= t; ++ti) {
cin >> n >> m;
if(n <= 4 && m <= 4) {
k = (1 << m);
fp = 0;
G(0);
cout << fp << "\n";
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
if(fps[i][j]) cout << "+";
else cout << "-";
}
cout << "\n";
}
} else {
if(n == 1) {
cout << m << "\n";
for(int i = 1; i <= m; ++i) {
cout << "-";
}
cout << "\n";
} else if(m == 1) {
cout << n << "\n";
for(int i = 1; i <= n; ++i) {
cout << "+";
cout << "\n";
}
} else {
int ns = (n - 1) / 2 * 2, ms = (m - 1) / 2 * 2;
cout << ns + ms << "\n";
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(i > ns) {
cout << "-";
} else if(j > ms) {
cout << "+";
} else {
cout << (((i + j) & 1) ? "-" : "+");
}
}
cout << "\n";
}
}
}
#ifdef WEEE
cout << flush;
#endif
}
cout << flush;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Wrong answer in test 20 2: 18 < 20 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong answer in test 20 2: 18 < 20 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
1388 KB |
Output is correct |
2 |
Correct |
28 ms |
1260 KB |
Output is correct |
3 |
Correct |
29 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
1316 KB |
Wrong answer in test 6 6: 8 < 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong answer in test 20 2: 18 < 20 |