#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 / 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 / 2; i++) {
for(int j = 0; j < M; j++) {
b[i][j] = 1;
}
}
}
else {
ans = N + M / 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 / 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
in the table A+B is not equal to 21 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Incorrect |
2 ms |
468 KB |
in the table A+B is not equal to 21 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
1732 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
1816 KB |
in the table A+B is not equal to 36 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Incorrect |
2 ms |
468 KB |
in the table A+B is not equal to 21 |
4 |
Halted |
0 ms |
0 KB |
- |