Submission #351754

#TimeUsernameProblemLanguageResultExecution timeMemory
351754cheissmartRed-blue table (IZhO19_stones)C++14
100 / 100
43 ms2284 KiB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1003;

char a[N][N];

void solve() {
	int n, m;
	cin >> n >> m;
	auto construct = [&] (int A, int B) {
		if(A == 0) {
			for(int i = 0; i < n; i++)
				for(int j = 0; j < m; j++)
					a[i][j] = '-';
			return;
		}
		if(B == 0) {
			for(int i = 0; i < n; i++)
				for(int j = 0; j < m; j++)
					a[i][j] = '+';
			return;
		}
		int have_plus = m - B;
		int need_plus_tot = (m + 2) / 2;
		int need_plus = need_plus_tot - have_plus;
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				a[i][j] = '-';
		for(int j = B; j < m; j++)
			for(int i = 0; i < n; i++)
				a[i][j] = '+';
		int pos = 0;
		for(int i = 0; i < A; i++) {
			for(int j = 0; j < need_plus; j++) {
				a[i][pos] = '+';
				pos = (pos + 1) % B;
			}
		}
	};
	int ans_A = 0, ans_B = 0;
	if(n > m) {
		ans_A = n, ans_B = 0;
	} else {
		ans_A = 0, ans_B = m;
	}
	for(int A = 1; A <= n; A++) {
		for(int B = 1; B <= m; B++) {
			int have_plus = m - B, have_minus = n - A;
			int need_plus_tot = (m + 2) / 2, need_minus_tot = (n + 2) / 2;
			int need_plus = max(0, need_plus_tot - have_plus), need_minus = max(0, need_minus_tot - have_minus);
			int put_plus = A * need_plus;
			int mx_plus_col = (put_plus + B - 1) / B;
			if(A - mx_plus_col < need_minus) continue;
			if(A + B > ans_A + ans_B) {
				ans_A = A, ans_B = B;
			}
		}
	}
 	cout << ans_A + ans_B << endl;
	construct(ans_A, ans_B);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++)
			cout << a[i][j];
		cout << '\n';
	}
}

signed main()
{
	IO_OP;

	int t;
	cin >> t;
	while(t--) {
		solve();
	}
	
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...