#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;
int v1 = n + m / 2, v2 = n / 2 + 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;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if (i % 2) b[i][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();
}
Compilation message
stones.cpp: In function 'void solve()':
stones.cpp:63:9: warning: unused variable 'v1' [-Wunused-variable]
63 | int v1 = n + m / 2, v2 = n / 2 + m;
| ^~
stones.cpp:63:25: warning: unused variable 'v2' [-Wunused-variable]
63 | int v1 = n + m / 2, v2 = n / 2 + m;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Wrong answer in test 4 4: 4 < 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Wrong answer in test 4 4: 4 < 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
1640 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 |
1956 KB |
Wrong answer in test 24 24: 24 < 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Wrong answer in test 4 4: 4 < 5 |
3 |
Halted |
0 ms |
0 KB |
- |