#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int n = 0, m = 0;
//
// cin >> n >> m;
//
// vector<vector<vector<int> > > ans;
//
// int ansval = 0;
//
// int tot = n * m;
//
// for(int it = 0; it < (1 << tot); it++) {
// vector<vector<int> > cur(n, vector<int>(m));
// for(int i = 0; i < n; i++)
// for(int j = 0; j < m; j++)
// cur[i][j] = ((it >> (i * m + j)) & 1);
// int a = 0, b = 0;
// for(int i = 0; i < n; i++) {
// int am0 = 0, am1 = 0;
// for(int j = 0; j < m; j++) { am0 += (cur[i][j] == 0); am1 += (cur[i][j] == 1); }
// a += (am1 > am0);
// }
// for(int j = 0; j < m; j++) {
// int am0 = 0, am1 = 0;
// for(int i = 0; i < n; i++) { am0 += (cur[i][j] == 0); am1 += (cur[i][j] == 1); }
// b += (am0 > am1);
// }
// if(a + b > ansval) {
// // ans.clear();
// // ans.pb(cur);
// ansval = a + b;
// }
// }
//
// cout << ansval << '\n';
//
// for(auto& x : ans) {
// for(auto& i : x) {
// for(auto& j : i) cout << (j == 0 ? '-' : '+');
// cout << endl;
// }
// cout << endl;
// }
int t = 0;
cin >> t;
while(t--) {
int n = 0, m = 0;
cin >> n >> m;
bool sw = false;
if(n > m) {
swap(n, m);
sw = true;
}
vector<vector<char> > ans(n, vector<char>(m, '-'));
vector<int> cntc(m);
int cpos = 0;
for(int i = 0; i < n; i++) {
int cur = 0;
for(int j = 0; j < m; j++) {
cpos = (cpos + 1) % m;
if(cntc[cpos] < (n - 1) / 2) {
ans[i][cpos] = '+';
cntc[cpos]++;
cur++;
if(cur == m / 2 + 1) break;
}
}
}
if(sw) {
vector<vector<char> > newans(m, vector<char>(n));
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
newans[i][j] = (ans[j][i] ^ '-' ^ '+');
swap(ans, newans);
swap(n, m);
}
int a = 0, b = 0;
for(int i = 0; i < n; i++) {
int am0 = 0, am1 = 0;
for(int j = 0; j < m; j++) { am0 += (ans[i][j] == '-'); am1 += (ans[i][j] == '+'); }
a += (am1 > am0);
}
for(int j = 0; j < m; j++) {
int am0 = 0, am1 = 0;
for(int i = 0; i < n; i++) { am0 += (ans[i][j] == '-'); am1 += (ans[i][j] == '+'); }
b += (am0 > am1);
}
cout << (a + b) << '\n';
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) cout << ans[i][j];
cout << endl;
}
}
return 0;
}
/*
0 = -
1 = +
*/
Compilation message
stones.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
10 ms |
364 KB |
Output is correct |
4 |
Correct |
18 ms |
396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
1412 KB |
Output is correct |
2 |
Correct |
44 ms |
1756 KB |
Output is correct |
3 |
Correct |
46 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
1388 KB |
Output is correct |
2 |
Correct |
37 ms |
1516 KB |
Output is correct |
3 |
Correct |
33 ms |
1352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
10 ms |
364 KB |
Output is correct |
4 |
Correct |
18 ms |
396 KB |
Output is correct |
5 |
Correct |
96 ms |
1412 KB |
Output is correct |
6 |
Correct |
44 ms |
1756 KB |
Output is correct |
7 |
Correct |
46 ms |
2668 KB |
Output is correct |
8 |
Correct |
61 ms |
1388 KB |
Output is correct |
9 |
Correct |
37 ms |
1516 KB |
Output is correct |
10 |
Correct |
33 ms |
1352 KB |
Output is correct |
11 |
Correct |
41 ms |
620 KB |
Output is correct |
12 |
Correct |
39 ms |
2092 KB |
Output is correct |
13 |
Correct |
45 ms |
1656 KB |
Output is correct |
14 |
Correct |
31 ms |
1316 KB |
Output is correct |
15 |
Correct |
42 ms |
2412 KB |
Output is correct |
16 |
Correct |
32 ms |
1932 KB |
Output is correct |
17 |
Correct |
16 ms |
1388 KB |
Output is correct |