#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;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
void solve(int test_case)
{
ll n,m; cin >> n >> m;
if(n == 1){
cout << m << endl;
rep1(j,m) cout << "-";
cout << endl;
return;
}
if(m == 1){
cout << n << endl;
rep1(i,n) cout << "+" << endl;
return;
}
if((n&1) and (m&1)){
ll a[n+5][m+5];
memset(a,0,sizeof a);
rep1(i,n) a[i][1] = 1;
rep1(i,n-1){
if(i&1){
for(int j = 2; j <= ceil2(m,2); ++j){
a[i][j] = 1;
}
}
else{
for(int j = ceil2(m,2)+1; j <= m; ++j){
a[i][j] = 1;
}
}
}
ll ans = n+m-2;
cout << ans << endl;
rep1(i,n){
rep1(j,m){
if(a[i][j] == 1) cout << "+";
else cout << "-";
}
cout << endl;
}
return;
}
if(min(n,m) <= 6){
bool swapped = false;
if(n < m){
swap(n,m);
swapped = true;
}
ll a[n+5][m+5];
memset(a,0,sizeof a);
if(m == 2){
rep1(i,n){
rep1(j,2){
a[i][j] = 1;
}
}
}
if(m == 3 or m == 4){
rep1(i,n){
rep1(j,m/2+1){
a[i][j] = 1;
}
}
}
if(m == 5 or m == 6){
rep1(i,n){
rep1(j,m/2){
a[i][j] = 1;
}
}
ll ptr = m/2+1;
ll cnt = 0;
rep1(i,n){
if((cnt+1)*2 >= n){
ptr++;
cnt = 0;
}
a[i][ptr] = 1;
cnt++;
}
}
ll ans = 0;
rep1(i,n){
ll cnt = 0;
rep1(j,m){
cnt += a[i][j];
}
if(cnt*2 > m) ans++;
}
rep1(j,m){
ll cnt = 0;
rep1(i,n){
cnt += a[i][j]^1;
}
if(cnt*2 > n) ans++;
}
cout << ans << endl;
if(!swapped){
rep1(i,n){
rep1(j,m){
if(a[i][j] == 1) cout << "+";
else cout << "-";
}
cout << endl;
}
}
else{
ll a2[m+5][n+5];
rep1(i,n) rep1(j,m) a2[j][i] = a[i][j];
swap(n,m);
rep1(i,n){
rep1(j,m){
if(a[i][j] == 1) cout << "+";
else cout << "-";
}
cout << endl;
}
}
return;
}
ll a[n+5][m+5];
n--, m--;
memset(a,0,sizeof a);
rep1(i,n+1) a[i][1] = 1;
rep1(i,n-1){
if(i&1){
for(int j = 2; j <= ceil2(m,2); ++j){
a[i][j] = 1;
}
}
else{
for(int j = ceil2(m,2)+1; j <= m; ++j){
a[i][j] = 1;
}
}
}
n++, m++;
rep1(i,n) a[i][m] = 1;
ll ans = n+m-4;
cout << ans << endl;
rep1(i,n){
rep1(j,m){
if(a[i][j] == 1) cout << "+";
else cout << "-";
}
cout << endl;
}
/*
int n,m; cin >> n >> m;
int a[n][m];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ans = 0;
rep(iter,1e7){
rep(i,n){
rep(j,m){
a[i][j] = rng()&1;
}
}
int val = 0;
rep(i,n){
int cnt_one = 0;
rep(j,m){
cnt_one += a[i][j];
}
if(cnt_one*2 > m){
val++;
}
}
rep(j,m){
int cnt_zero = 0;
rep(i,n){
cnt_zero += a[i][j]^1;
}
if(cnt_zero*2 > n){
val++;
}
}
amax(ans,val);
// if(val == 10){
// rep(i,n){
// rep(j,m){
// cout << a[i][j];
// }
// cout << endl;
// }
// cout << endl;
// }
}
cout << ans << endl;
*/
}
int main()
{
fastio;
int t = 1;
cin >> t;
rep1(i, t) {
solve(i);
}
return 0;
}
Compilation message
stones.cpp: In function 'void solve(int)':
stones.cpp:183:16: warning: variable 'a2' set but not used [-Wunused-but-set-variable]
183 | ll a2[m+5][n+5];
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
in the table A+B is not equal to 50 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1372 KB |
Output is correct |
2 |
Correct |
19 ms |
6412 KB |
Output is correct |
3 |
Correct |
17 ms |
7000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1456 KB |
Output is correct |
2 |
Correct |
16 ms |
5376 KB |
Output is correct |
3 |
Correct |
13 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |