# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167946 | YottaByte | Red-blue table (IZhO19_stones) | C++14 | 0 ms | 0 KiB |
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>
using namespace std;
#define ll long long
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define endl "\n"
#define METH ios::sync_with_stdio(0); cin.tie(0);
#define BEGIN cout << "BEGIN" << endl;
#define END cout << "END" << endl;
const int mod = 1e9 + 7; /// ANOTHER HASH MOD: 228228227
const int prime = 29; /// ANOTHER HASH PRIME: 997
const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8);
int n, m;
inline void purify() {
}
inline void precalc() {
}
inline void read() {
scanf("%d %d", &n, &m);
}
inline int check(int mask) {
int res = 0;
for (int i = 0; i < n; i++) {
int cnta = 0;
for (int j = 0; j < m; j++) {
if (mask >> (j + i * m) & 1) {
cnta++;
}
}
if (cnta > m / 2) {
res++;
}
}
for (int i = 0; i < m; i++) {
int cntb = 0;
for (int j = 0; i + j < m * n; j += m) {
if (!(mask >> (j + i) & 1)) {
cntb++;
}
}
if (cntb > n / 2) {
res++;
}
}
return res;
}
void out(int mask) {
for (int i = 0; i < n * m; i++) {
if (mask >> i & 1) {
cout << '+';
} else {
cout << '-';
}
if ((i + 1) % m == 0) {
cout << endl;
}
}
}
inline void solve() {
if (n * m > 20) {
break;
}
int ansab = 0, ans = -1;
for (int i = 0; i < (1 << (n * m)); i++) {
if (ansab < check(i)) {
ansab = check(i);
ans = i;
}
}
cout << ansab << endl;
out(ans);
}
int main() {
int t;
scanf("%d", &t);
//precalc();
while (t--) {
//purify();
read();
solve();
}
}