#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
//#define int ll
const int N = 1005;
const int oo = 1e9 + 5;
int n, m, cnt[N];
char a[N][N];
void solve() {
cin >> n >> m;
int ans = 0;
if (n >= m) {
ans += n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
a[i][j] = '+';
}
}
int pr = (n * ((m - 1) / 2)) / (n / 2 + 1);
/*if (m <= 3) { pr = m / 2; }
else if (m == 4) { pr = m / 2 - 1; }
else if (m == 5) { pr = m / 2 + 1; }
else if (m % 2 == 1) { pr = m; }
else if (m % 2 == 0) { pr = m / 2; }*/
int pos = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= (m - 1) / 2; ++j) {
a[i][pos] = '-';
++cnt[pos];
++pos;
if (pos == pr + 1) { pos = 1; }
}
}
for (int i = 1; i <= pr; ++i) {
if (cnt[i] >= (n / 2) + 1) { ++ans; }
cnt[i] = 0;
}
}
else {
ans += m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
a[i][j] = '-';
}
}
int pr = (m * ((n - 1) / 2)) / (m / 2 + 1);
/*if (n <= 3) { pr = n / 2; }
else if (n == 4) { pr = n / 2 - 1; }
else if (n == 5) { pr = n / 2 + 1; }
else if (n % 2 == 1) { pr = n / 2 + 2; }
else if (n % 2 == 0) { pr = n / 2; }*/
int pos = 1;
for (int j = 1; j <= m; ++j) {
for (int i = 1; i <= (n - 1) / 2; ++i) {
a[pos][j] = '+';
++cnt[pos];
++pos;
if (pos == pr + 1) { pos = 1; }
}
}
for (int i = 1; i <= pr; ++i) {
if (cnt[i] >= (m / 2) + 1) { ++ans; }
cnt[i] = 0;
}
}
cout << ans <<"\n";
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cout << a[i][j];
}
cout <<"\n";
}
}
main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tests = 1;
cin >> tests;
while (tests --) { solve(); }
return 0;
}
/*
Just Chalish!
*/
Compilation message
stones.cpp:115:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
115 | main () {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1516 KB |
Output is correct |
2 |
Correct |
31 ms |
2028 KB |
Output is correct |
3 |
Correct |
29 ms |
2156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
1536 KB |
Output is correct |
2 |
Correct |
31 ms |
2020 KB |
Output is correct |
3 |
Correct |
26 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
35 ms |
1516 KB |
Output is correct |
6 |
Correct |
31 ms |
2028 KB |
Output is correct |
7 |
Correct |
29 ms |
2156 KB |
Output is correct |
8 |
Correct |
33 ms |
1536 KB |
Output is correct |
9 |
Correct |
31 ms |
2020 KB |
Output is correct |
10 |
Correct |
26 ms |
1644 KB |
Output is correct |
11 |
Correct |
9 ms |
620 KB |
Output is correct |
12 |
Correct |
26 ms |
1900 KB |
Output is correct |
13 |
Correct |
28 ms |
2028 KB |
Output is correct |
14 |
Correct |
21 ms |
1772 KB |
Output is correct |
15 |
Correct |
35 ms |
2412 KB |
Output is correct |
16 |
Correct |
31 ms |
1900 KB |
Output is correct |
17 |
Correct |
12 ms |
1388 KB |
Output is correct |