/*
,----.. ____ ,----..
,--, ,--, / / \ .--.--. ,----.. ,---,. ,---, ,---,. ,' , `.,-.----. ,---,. / / \
|'. \ / .`| / . : / / '. / / \ ,' .' | .' .' `\ ,' .' | ,-+-,.' _ |\ / \ ,--, ,' .' | / . :
; \ `\ /' / ; . / ;. \ : /`. / / . : ,---.' |,---.' \ ,---.' | ,-+-. ; , ||; : \ ,'_ /|,---.' | . / ;. \
`. \ / / .'. ; / ` ; | |--` . / ;. \ | | .'| | .`\ || | .' ,--.'|' | ;|| | .\ : .--. | | :| | .'. ; / ` ;
\ \/ / ./ ; | ; \ ; | : ;_ . ; / ` ; : : |-,: : | ' |: : |-,| | ,', | ':. : |: | ,'_ /| : . |: : : ; | ; \ ; |
\ \.' / | : | ; | '\ \ `. ; | ; \ ; | : | ;/|| ' ' ; :: | ;/|| | / | | ||| | \ : | ' | | . .: | |-,| : | ; | '
\ ; ; . | ' ' ' : `----. \| : | ; | ' | : .'' | ; . || : .'' | : | : |,| : . / | | ' | | || : ;/|. | ' ' ' :
/ \ \ \ ' ; \; / | __ \ \ |. | ' ' ' : | | |-,| | : | '| | |-,; . | ; |--' ; | | \ : | | : ' ;| | .'' ; \; / |
; /\ \ \ \ \ ', / / /`--' /' ; \; / | ' : ;/|' : | / ; ' : ;/|| : | | , | | ;\ \| ; ' | | '' : ' \ \ ', /
./__; \ ; \ ; : / '--'. / \ \ ', . \| | \| | '` ,/ | | \| : ' |/ : ' | \.': | : ; ; || | | ; : /
| : / \ \ ; \ \ .' `--'---' ; : ; | : .'; : .' | : .'; | |`-' : : :-' ' : `--' \ : \ \ \ .'
; |/ \ ' | `---` \ \ .'`--"| | ,' | ,.' | | ,' | ;/ | |.' : , .-./ | ,' `---`
`---' `--` `---` `----' '---' `----' '---' `---' `--`----' `----' */
//Author RufatM
/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("inline")
#pragma GCC optimize("tree-vectorize")
#pragma GCC optimize("loop-vectorize")
#pragma GCC optimize("loop-interchange")
#pragma GCC optimize("loop-block")
#pragma GCC optimize("loop-strip-mine")
#pragma GCC optimize("loop-optimize")
#pragma GCC optimize("tree-loop-distribute-patterns")
#pragma GCC optimize("tree-loop-distribute-force")
#pragma GCC optimize("tree-loop-distribute")
#pragma GCC optimize("tree-loop-vectorize")
#pragma GCC optimize("tree-loop-ivcanon")
#pragma GCC optimize("tree-loop-ivopts")
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<pii>> vvp;
typedef vector<bool> vb;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define mt19937_64 mt_rand(chrono::steady_clock::now().time_since_epoch().count())
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
template<typename T> bool isPrime(T n) { if (n <= 1)return false;if (n <= 3)return true;if (n % 2 == 0 || n % 3 == 0)return false;for (T i = 5;i * i <= n;i += 6)if (n % i == 0 || n % (i + 2) == 0)return false;return true; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int LOG = 21;
const long long LINF = 1e18 + 7;
const int MAXN = 1e5 + 7;
signed main(){
fastio;
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
if(n == 1){
cout << m << endl;
cout << string(m, '-') << endl;
continue;
}
if(m == 1){
cout << n << endl;
for(int i = 0; i < n; i++){
cout << "+" << endl;
}
continue;
}
int dmax = (m - 1) / 2;
int need = (n / 2) + 1;
int best = -1, bestk = 0, bestb = 0;
for(int k = 0; k <= n; k++){
ll total = ll(k) * dmax + ll(n - k) * m;
ll b = total / need;
if(b > m) b = m;
int score = k + b;
if(score > best){
best = score;
bestk = k;
bestb = b;
}
}
vs g(n, string(m, '+'));
vector<int> cap(n);
for(int i = 0; i < n; i++){
cap[i] = (i < bestk ? dmax : m);
}
priority_queue<pii> pq;
for(int i = 0; i < n; i++){
if(cap[i] > 0) pq.push({cap[i], i});
}
for(int j = 0; j < bestb; j++){
int rem = need;
while(rem--){
auto [c, i] = pq.top(); pq.pop();
g[i][j] = '-';
c--;
if(c > 0) pq.push({c, i});
}
}
cout << best << endl;
for(int i = 0; i < n; i++){
cout << g[i] << endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |