This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
stones.cpp:115:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
115 | main () {
| ^
# | 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... |