#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <iomanip>
#include <stdio.h>
#include <ctime>
#include <fstream>
#include <chrono>
#define _GLIBCXX_DEBUG
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define pb push_back;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"
typedef int supertype;
using namespace std;
vector <vector <bool>> generate(int mask, int n, int m) {
vector <vector <bool>> ans(n, vector <bool>(m));
int cut = (1LL << n) - 1;
for (int i = 0; i < n; i++) {
int nowString = mask >> (i * m) & cut;
for (int j = 0; j < m; j++) {
ans[n - i - 1][m - j - 1] = nowString >> j & 1;
}
}
return ans;
}
void print(vector <vector <bool>>& ans) {
for (int i = 0; i < ans.size(); i++) {
for (int j = 0; j < ans[i].size(); j++) {
if (ans[i][j])
cout << '+';
else
cout << '-';
}
cout << endl;
}
}
void solve() {
int n, m;
cin >> n >> m;
int best = 0, bestmask = 0;
for (int mask = 0; mask < (1LL << (n * m)); mask++) {
auto now = generate(mask, n, m);
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
int red = 0;
for (int j = 0; j < m; j++) {
if (now[i][j])
red++;
}
if (red > m - red)
a++;
}
for (int j = 0; j < m; j++) {
int blue = 0;
for (int i = 0; i < n; i++) {
if (!now[i][j])
blue++;
}
if (blue > n - blue)
b++;
}
if (a + b > best) {
best = a + b;
bestmask = mask;
}
}
cout << best << endl;
auto ans = generate(bestmask, n, m);
print(ans);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(time(NULL));
//freopen("sort.in", "r", stdin);
//freopen("sort.in", "r", stdin);
//int n, m, mask;
//cin >> n >> m >> mask;
//print(generate(mask, n, m));
int tests = 1;
cin >> tests;
while (tests--) {
solve();
}
return 0;
}
/*
*/
Compilation message
stones.cpp: In function 'void print(std::vector<std::vector<bool> >&)':
stones.cpp:48:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans.size(); i++) {
~~^~~~~~~~~~~~
stones.cpp:49:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < ans[i].size(); j++) {
~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
33 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2066 ms |
248 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
33 ms |
376 KB |
Output is correct |
3 |
Execution timed out |
2066 ms |
248 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2064 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
33 ms |
376 KB |
Output is correct |
3 |
Execution timed out |
2066 ms |
248 KB |
Time limit exceeded |