/*Bismillahir Rahmanir Raheem*/
#include <bits/stdc++.h>
using namespace std;
#define kuka ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
#define pb push_back
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define FOR(n) for(int i = 0; i < n; i++)
#define ff(x, y) for( int y = 0; y < x; y++)
#define fff(x, y) for( int y = x; y <= 0; y--)
#define F first
#define S second
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = LLONG_MAX;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
char a[1002][1002];
int col[1001], mp[1001];
void oyan(){
int n, m, mx, ans = 0;
cin>>n>>m;
if(n <= m){
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
a[i][j] = '-';
col[j] = (n - 1) / 2;
}
}
mp[(n - 1) / 2] = m;
mx = (n - 1) / 2 ;
for(int i = 1; i <= n; i++){
int sum = 0, colmx = m / 2 + 1;
if(mp[mx] <= (m / 2) + 1){
colmx-=mp[mx];
mp[mx] = 0;
mx--;
}
//cout<<mx<<"\n";
for(int j = 1; j <= m; j++){
if(sum > m / 2){
ans++;sum = 0;
break;
}
if(col[j] > mx and col[j] != 0){
col[j] --;
mp[col[j]]++;
a[i][j] = '+';
sum++;
}
if(col[j] == mx and col[j] != 0){
if(!colmx)continue;
mp[col[j]]--;
col[j]--;
mp[col[j]]++;
a[i][j] = '+';
sum++;
colmx--;
}
//cout<<col[j]<< " "<<sum<<" "<<colmx<<"\n";
}
if(sum > m / 2){
ans++;sum = 0;
}
}
ans+=m;
}else{
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
a[i][j] = '+';
}
col[i] = (m - 1) / 2;
}
mp[(m - 1) / 2] = n;
mx = (m - 1) / 2;
for(int j = 1; j <= m; j++){
int sum = 0, colmx = n / 2 + 1;
if(mp[mx] <= (n / 2) + 1){
colmx-=mp[mx];
mp[mx] = 0;
mx--;
}
//cout<<mx<<"\n";
for(int i = 1; i <= n; i++){
if(sum > n / 2){
ans++;sum = 0;
break;
}
if(col[i] > mx and col[i] != 0){
col[i] --;
mp[col[i]]++;
a[i][j] = '-';
sum++;
}
if(col[i] == mx and col[i] != 0){
if(!colmx)continue;
mp[col[i]]--;
col[i]--;
mp[col[i]]++;
a[i][j] = '-';
sum++;
colmx--;
}
//cout<<col[j]<< " "<<sum<<" "<<colmx<<"\n";
}
if(sum > n / 2){
ans++;sum = 0;
}
}
ans+=n;
}
cout<<ans<<"\n";
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j++){
cout<<a[i][j];
}
cout<<"\n";
}
}
main(){
//kuka;
//freopen("test.txt", "r", stdin);
//freopen("distance.in", "r", stdin);
//freopen("distance.out", "w", stdout);
int oylan = 1;
cin>>oylan;
while(oylan--){
oyan();
}
}
/*
NOTES
a/b module == (a*b^(module - 2)) % (module);
*/
Compilation message
stones.cpp:131:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
131 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1584 KB |
Output is correct |
2 |
Correct |
20 ms |
1872 KB |
Output is correct |
3 |
Correct |
18 ms |
2128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1360 KB |
Output is correct |
2 |
Correct |
18 ms |
1872 KB |
Output is correct |
3 |
Correct |
20 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
23 ms |
1584 KB |
Output is correct |
6 |
Correct |
20 ms |
1872 KB |
Output is correct |
7 |
Correct |
18 ms |
2128 KB |
Output is correct |
8 |
Correct |
25 ms |
1360 KB |
Output is correct |
9 |
Correct |
18 ms |
1872 KB |
Output is correct |
10 |
Correct |
20 ms |
1616 KB |
Output is correct |
11 |
Correct |
9 ms |
592 KB |
Output is correct |
12 |
Correct |
18 ms |
2008 KB |
Output is correct |
13 |
Correct |
18 ms |
2128 KB |
Output is correct |
14 |
Correct |
14 ms |
1616 KB |
Output is correct |
15 |
Correct |
22 ms |
2384 KB |
Output is correct |
16 |
Correct |
17 ms |
1884 KB |
Output is correct |
17 |
Correct |
9 ms |
1360 KB |
Output is correct |