This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |