# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
167947 | YottaByte | Red-blue table (IZhO19_stones) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
if (n * m > 20) {
return;
}
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();
}
}