#include <bits/stdc++.h>
#define sz(x) (long long)x.size()
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};
void debug() {
cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
cerr << a << " ";
debug(b...);
}
long long div_ceil(long long a, long long b) {
return (a + b - 1) / b;
}
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
long long q; cin >> q;
while(q--) {
long long n, m, ans = 0; cin >> n >> m;
vector<vector<long long>> result(n, vector<long long>(m));
for(long long mask = 0; mask < (1 << (n * m)); mask++) {
vector<vector<long long>> a(n, vector<long long>(m));
for(long long i = 0; i < n; i++) {
for(long long j = i * m; j < (i + 1) * m; j++) {
a[i][j % m] = (mask & (1 << j)) > 0;
}
}
vector<long long> rows(n), cols(m);
for(long long i = 0; i < n; i++) {
for(long long j = 0; j < m; j++) {
if(a[i][j] == 1) {
rows[i]++;
}
else {
cols[j]++;
}
}
}
long long res = 0;
for(long long i = 0; i < n; i++) {
if(rows[i] >= m / 2 + 1) {
res++;
}
}
for(long long j = 0; j < m; j++) {
if(cols[j] >= n / 2 + 1) {
res++;
}
}
if(res > ans) {
result = a;
ans = res;
}
}
cout << ans << "\n";
for(long long i = 0; i < n; i++) {
for(long long j = 0; j < m; j++) {
cout << (result[i][j] ? '+' : '-');
}
cout << "\n";
}
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
27 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2076 ms |
492 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
27 ms |
492 KB |
Output is correct |
3 |
Execution timed out |
2076 ms |
492 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2069 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2066 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
27 ms |
492 KB |
Output is correct |
3 |
Execution timed out |
2076 ms |
492 KB |
Time limit exceeded |