제출 #167489

#제출 시각아이디문제언어결과실행 시간메모리
167489LightningRed-blue table (IZhO19_stones)C++14
100 / 100
35 ms3320 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#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 show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2000;
const int INF = 1e9;

char a[N][N];
int cnt[N];

void solve(int n, int m) {
	if(n >= m) {
		fo(i, 1, n, 1) {
			fo(j, 1, m, 1) {
				a[i][j] = '+';
			}
		}
		int need = (n / 2 + 1);
		int mx = m - (m / 2 + 1);
		int pos = 1;
		int ans = 0;
		fo(j, 1, m, 1) {
			bool ok = 1;
			fo(it, 1, need, 1) {
				if(cnt[pos] < mx) {
					a[pos][j] = '-';	
					++cnt[pos];
					++pos;
					if(pos == n + 1) pos = 1;
				} else ok = 0;
			}
			ans += ok;
		}
		cout << n + ans <<'\n';
		fo(i, 1, n, 1) {
			cnt[i] = 0;
			fo(j, 1, m, 1) {
				cout << a[i][j];
			}
			cout << '\n';
		}
	} else {
		fo(i, 1, n, 1) {
			fo(j, 1, m, 1) {
				a[i][j] = '-';
			}
		}
		int need = (m / 2 + 1);
		int mx = n - (n / 2 + 1);
		int pos = 1;
		int ans = 0;
		fo(i, 1, n, 1) {
			bool ok = 1;
			fo(it, 1, need, 1) {
				if(cnt[pos] < mx) {
					a[i][pos] = '+';	
					++cnt[pos];
					++pos;
					if(pos == m + 1) pos = 1;
				} else ok = 0;
			}
			ans += ok;
		}
		cout << m + ans <<'\n';
		fo(i, 1, n, 1) {
			fo(j, 1, m, 1) {
				cout << a[i][j];
				cnt[j] = 0;
			}
			cout << '\n';
		}
	}
}

int t;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> t;
	fo(it, 1, t, 1) {
		int n, m;
		cin >> n >> m;
		solve(n, m);
	}
	return 0;
}









#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...