#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) (v).begin(), (v).end()
void solve() {
int n, m;
cin >> n >> m;
int mx = 0;
for (int mk = 0; mk < 1 << n * m; mk++) {
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n * m; i++)
a[i / m][i % m] = (mk >> i) & 1;
int scr = 0;
for (int i = 0; i < n; i++)
scr += (count(all(a[i]), 0) > count(all(a[i]), 1));
for (int i = 0; i < m; i++) {
vector<int> cnt(2);
for (int j = 0; j < n; j++)
cnt[a[j][i]]++;
scr += (cnt[1] > cnt[0]);
}
mx = max(mx, scr);
}
cout << mx << '\n';
for (int mk = 0; mk < 1 << n * m; mk++) {
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n * m; i++)
a[i / m][i % m] = (mk >> i) & 1;
int scr = 0;
for (int i = 0; i < n; i++)
scr += (count(all(a[i]), 0) > count(all(a[i]), 1));
for (int i = 0; i < m; i++) {
vector<int> cnt(2);
for (int j = 0; j < n; j++)
cnt[a[j][i]]++;
scr += (cnt[1] > cnt[0]);
}
if (scr == mx) {
for (auto i : a) {
for (auto j : i)
cout << (j ? '-' : '+');
cout << '\n';
}
return;
cout << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int T;
cin >> T;
while (T--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
17 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2035 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
17 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
2035 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2054 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2035 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
17 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
2035 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |