#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int tt;
cin >> tt;
while (tt--) {
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
int max1 = 0;
for (int mask = 0; mask < (1 << (n * m)); ++mask) {
for (int k = 0; k < (n * m); ++k) {
if ((mask & (1 << k)))a[k / m][k % m] = 1;
else a[k / m][k % m] = 0;
}
int cur = 0;
for (int i = 0; i < n; ++i) {
int x = 0;
for (int j = 0; j < m; ++j) {
if (a[i][j]) x++;
else x--;
}
if (x > 0) cur++;
}
for (int j = 0; j < m; ++j) {
int x = 0;
for (int i = 0; i < n; ++i) {
if (a[i][j]) x++;
else x--;
}
if (x < 0) cur++;
}
if (cur > max1) {
max1 = cur;
}
}
cout << max1 << endl;
for (int mask = 0; mask < (1 << (n * m)); ++mask) {
for (int k = 0; k < (n * m); ++k) {
if ((mask & (1 << k)))a[k / m][k % m] = 1;
else a[k / m][k % m] = 0;
}
int cur = 0;
for (int i = 0; i < n; ++i) {
int x = 0;
for (int j = 0; j < m; ++j) {
if (a[i][j]) x++;
else x--;
}
if (x > 0) cur++;
}
for (int j = 0; j < m; ++j) {
int x = 0;
for (int i = 0; i < n; ++i) {
if (a[i][j]) x++;
else x--;
}
if (x < 0) cur++;
}
if (cur == max1) {
for (auto elem : a) {
for (auto u : elem) {
if (u) cout << "+";
else cout << "-";
}
cout << endl;
}
cout << endl;
break;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
10 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2067 ms |
376 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
10 ms |
364 KB |
Output is correct |
3 |
Execution timed out |
2067 ms |
376 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2087 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
10 ms |
364 KB |
Output is correct |
3 |
Execution timed out |
2067 ms |
376 KB |
Time limit exceeded |