#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1005;
int a[MAX_N][MAX_N], b[MAX_N][MAX_N];
void solve(int N, int M) {
int ans = 0;
if(N <= 4 and M <= 4) {
for(int mask = 0; mask < (1<<(N * M)); mask++) {
int sum = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(mask & (1<<(i * M + j))) {
a[i][j] = 1;
}
else {
a[i][j] = 0;
}
}
}
for(int i = 0; i < N; i++) {
int cnt1 = 0;
for(int j = 0; j < M; j++) {
cnt1 += a[i][j];
}
sum += (cnt1 > M - cnt1);
}
for(int j = 0; j < M; j++) {
int cnt1 = 0;
for(int i = 0; i < N; i++) {
cnt1 += a[i][j];
}
sum += (N - cnt1 > cnt1);
}
if(ans < sum) {
ans = sum;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
b[i][j] = a[i][j];
}
}
}
}
}
else {
if(N < M) {
ans = M + (N - 1) / 2;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
b[i][j] = 0;
}
}
for(int i = 0; i < (N - 1) / 2; i++) {
for(int j = 0; j < M; j++) {
b[i][j] = 1;
}
}
}
else {
ans = N + (M - 1) / 2;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
b[i][j] = 1;
}
}
for(int j = 0; j < (M - 1) / 2; j++) {
for(int i = 0; i < N; i++) {
b[i][j] = 0;
}
}
}
}
cout << ans << '\n';
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(b[i][j] == 1) {
cout << '+';
}
else {
cout << '-';
}
}
cout << '\n';
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T;
cin >> T;
while(T--) {
int N, M;
cin >> N >> M;
solve(N, M);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Incorrect |
7 ms |
584 KB |
Wrong answer in test 5 29: 31 < 32 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
1732 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
1824 KB |
Wrong answer in test 24 24: 35 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Incorrect |
7 ms |
584 KB |
Wrong answer in test 5 29: 31 < 32 |
5 |
Halted |
0 ms |
0 KB |
- |