#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1000 + 100, M = 500 + 10, len = 315, inf = 1e18;
const ll mod = 998244353;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll bp(ll x, ll step){
ll res = 1;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
ll inv(ll x){
return bp(x, mod - 2);
}
ll n, m, a, b;
char arr[N][N];
int check1(){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
arr[i][j] = '+';
}
}
for(int i = 0; i < n - a; i++){
for(int j = 0; j < m; j++){
arr[i][j] = '-';
}
}
int start = n - a;
for(int j = 0; j < b; j++){
//cout << n/2 + 1 - a << endl;
for(int i = 0; i < (n/2 + 1) - (n - a); i++){
//cout << start << " " << j << endl;
arr[start][j] = '-';
if(++start == n) start = n - a;
}
}
int ans = 0;
for(int i = 0; i < n; i++){
int cnt = 0;
for(int j = 0; j < m; j++){
if(arr[i][j] == '+') cnt++;
}
if(cnt >= m/2 + 1) ans++;
}
for(int j = 0; j < m; j++){
int cnt = 0;
for(int i = 0; i < n; i++){
if(arr[i][j] == '-') cnt++;
}
if(cnt >= n/2 + 1) ans++;
}
return ans;
}
int check2(){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
arr[i][j] = '-';
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m - b; j++){
arr[i][j] = '+';
}
}
int start = m - b;
for(int j = 0; j < a; j++){
for(int i = 0; i < (m/2 + 1) - (m - b); i++){
arr[j][start] = '+';
if(++start == m) start = m - b;
}
}
int ans = 0;
for(int i = 0; i < n; i++){
int cnt = 0;
for(int j = 0; j < m; j++){
if(arr[i][j] == '+') cnt++;
}
if(cnt >= m/2 + 1) ans++;
}
//cout << ans << endl;
for(int j = 0; j < m; j++){
int cnt = 0;
for(int i = 0; i < n; i++){
if(arr[i][j] == '-') cnt++;
}
if(cnt >= n/2 + 1) ans++;
}
return ans;
}
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//cout.tie(nullptr);
int tt;
cin >> tt;
while(tt--){
int a1, b1;
cin >> n >> m;
int mx = 0;
for(int i = 0; i <= n; i++){
int cur = i + min((n * m - (m/2 + 1) * i) / (n/2 + 1), m);
//cout << cur << " "<< i << " " << min((n * m - (m/2 + 1) * i) / (n/2 + 1), m) << endl;
if(cur > mx){
mx = cur;
a = i;
b = min((n * m - (m/2 + 1) * i) / (n/2 + 1), m);
}
if(cur == mx){
a1 = i;
b1 = min((n * m - (m/2 + 1) * i) / (n/2 + 1), m);
}
}
//cout << n << " "<< m << " " << mx << endl;
//if(mx != 19) continue;
//cout << a << " "<< b << endl;
cout << mx << endl;
if(check1() != mx){
if(check2() != mx){
a = a1;
b = b1;
if(check1() != mx){
if(check2() != mx){
//cout << n << " "<< m << " Conf\n";
//return 0;
}
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << arr[i][j];
}
cout << endl;
}
}
return 0;
}
# | 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... |