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<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;
}
}
}
}
# | 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... |