#pragma GCC optimize ("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#include <chrono>
#include <thread>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define speed ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i,a,b) for(int i = a;i <= b ;i++)
#define rev(i,a,b) for(int i =a ;i<= b ; i--)
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define pss pair<string,string>
#define pii pair<int,int>
#define vi vector <int>
#define ull unsigned ll
#define pll pair<ll,ll>
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define ll long long
#define pb push_back
#define pbb pop_back
#define endl '\n'
#define S second
#define F first
// #define int ll
const int modinput = 1000003;
const int mod = 1000000007;
const int modq = 998244353;
const int inf = 0x3F3F3F3F;
const int sz = 1e5+5;
const ll iinf = 1e18;
const int N = 200005;
const int MAX = 202;
const int sz1 = 505;
const ld eps = 1e-9;
vector<vector<pair<int,int>>>g;
std::vector<int>dist;
std::vector<int>path;
std::deque<int> q;
std::vector<int> w;
unordered_map<ll, int> mp;
void solve()
{
int n,m;
cin>>n>>m;
int n1 = n,m1 = m;
bool flag = 0;
if(m < n){
swap(n,m);
flag = 1;
}
int a[1010][1010],cnt[1010];
int ans = m;
for (int i = 1; i <= n; i++ ){
for (int j = 1; j <= m; j++ ){
a[i][j] = 0;
cnt[j] = 0;
}
}
for (int i = 1; i <= n; i++ ){
int cur = 0;
vector<pii> v;
for (int j = 1; j <= m; j++ ){
if((cnt[j] + 1) * 2 < n){
v.push_back({cnt[j], j});
}
}
if (v.size() * 2 <= m)
break;
sort(all(v));
for (int j = 0; ; j++ ){
a[i][v[j].second] = 1;
cnt[v[j].second] ++;
if((j + 1) * 2 > m)
break;
}
ans ++;
}
cout<<ans<<endl;
if(flag){
swap(n, m);
flag = true;
}
for (int i = 1; i <= n; i++ ){
for (int j = 1; j <= m; j++ ){
if(flag)
cout<<(a[j][i] ? '-' : '+');
else
cout<<(a[i][j] ? '+' : '-');
}
cout<<endl;
}
///cout<<endl;
}//1 2 2 4 7 7
signed main() {
speed
int T = 1,X_X = 0;
cin>>T;
for (int cs = 1; cs <= T; cs++) {
//cout << "Case " << cs << ": ";
solve();
}
//ll n, l, r;
//while ( cin >> n >> l >> r /* and (n || m) */){
// cin >> m;
// solve(n, l, r);
//}
return 0;
}//429
# | 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... |