#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 1e9 + 7;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2e5 + 10;
int count(vec<vec<int>> &a)
{
int n = sz(a), m = sz(a[0]);
int res = 0;
for (int i = 0; i < n; i++)
{
int r = 0, b = 0;
for (int j = 0; j < m; j++)
{
if (a[i][j] == 1) r++;
else b++;
}
res += r > b;
}
for (int j = 0; j < m; j++)
{
int r = 0, b = 0;
for (int i = 0; i < n; i++)
{
if (a[i][j] == 1) r++;
else b++;
}
res += b > r;
}
return res;
}
void solve()
{
int n, m;
cin >> n >> m;
if (n % 2 && m % 2)
{
if (m == 1)
{
cout << n << "\n";
for (int i = 0; i < n; i++) cout << "+\n";
return;
}
if (n == 1) cout << m << "\n";
else cout << n + m - 2 << "\n";
for (int i = 0; i < n / 2; i++)
{
for (int j = 0; j <= m / 2; j++) cout << '+';
for (int j = m / 2 + 1; j < m; j++) cout << '-';
cout << "\n";
}
for (int i = 0; i < n / 2; i++)
{
cout << '+';
for (int j = 1; j <= m / 2; j++) cout << '-';
for (int j = m / 2 + 1; j < m; j++) cout << '+';
cout << "\n";
}
for (int j = 0; j < m; j++) cout << '-';
cout << "\n";
return;
}
vec<vec<int>> ans(n, vec<int>(m));
for (int mask = 0; mask < (1 << n * m); mask++)
{
vec<vec<int>> a(n, vec<int>(m));
for (int i = 0; i < n * m; i++)
{
if ((mask >> i) & 1)
{
int x = i / m, y = i % m;
a[x][y] = 1;
}
}
if (count(a) > count(ans)) ans = a;
}
cout << count(ans) << "\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (ans[i][j] == 1) cout << '+';
else cout << '-';
}
cout << "\n";
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
24 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2059 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
24 ms |
324 KB |
Output is correct |
3 |
Execution timed out |
2059 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1236 KB |
Output is correct |
2 |
Correct |
23 ms |
1188 KB |
Output is correct |
3 |
Correct |
19 ms |
1120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2068 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
24 ms |
324 KB |
Output is correct |
3 |
Execution timed out |
2059 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |