#include <bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
//using namespace __gnu_pbds;
//template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 gen(time(0));
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define sz(a) int32_t(a.size())
#define endl '\n'
//#define int long long
const int N = 5e5 + 100;
const int M = 31;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
int calc(vector < vector < int > > a)
{
int ans = 0;
for(int i = 0; i < sz(a); i++)
{
int x = 0, y = 0;
for(int j = 0; j < sz(a[i]); j++)
{
if (a[i][j]) x++;
else y++;
}
ans += (x > y);
}
for(int j = 0; j < sz(a[0]); j++)
{
int x = 0, y = 0;
for(int i = 0; i < sz(a); i++)
{
if (a[i][j]) y++;
else x++;
}
ans += (x > y);
}
return ans;
}
void solve()
{
int n, m;
cin >> n >> m;
vector < vector < int > > a(n, vector < int > (m, 0)), b = a, c = a, d(n, vector < int > (m, 1));
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if (j % 2 == 0) a[i][j] = 1;
if (m % 2 == 0)
{
for(int i = 0; i < n; i++)
a[i][m - 1] = 1;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if (i % 2) b[i][j] = 1;
if (n % 2 == 0)
{
for(int j = 0; j < m; j++)
b[0][j] = 1;
}
if (calc(b) > calc(a)) a = b;
if (calc(c) > calc(a)) a = c;
if (calc(d) > calc(a)) a = d;
cout << calc(a) << endl;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if (a[i][j]) cout << "+";
else cout << "-";
}
cout << endl;
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
int T;
cin >> T;
while (T--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Incorrect |
6 ms |
436 KB |
Wrong answer in test 4 25: 25 < 26 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
1644 KB |
Wrong answer in test 97 21: 107 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
1868 KB |
Wrong answer in test 24 24: 35 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
5 ms |
460 KB |
Output is correct |
4 |
Incorrect |
6 ms |
436 KB |
Wrong answer in test 4 25: 25 < 26 |
5 |
Halted |
0 ms |
0 KB |
- |