답안 #556086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556086 2022-05-02T10:32:02 Z ngpin04 Red-blue table (IZhO19_stones) C++14
100 / 100
36 ms 3248 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end() 
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
const int N = 2005;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);

int n,m;

char a[N][N];

int check(int cnt) {
	if (2 * cnt < m)
		return cnt + n;
	int x = (m / 2 + 1) - (m - cnt);
	int lef = (n - 1) >> 1;
	for (int i = n; i >= 0; i--) 
		if ((x * i + cnt - 1) / cnt <= lef)
			return i + cnt;
	assert(false);
	return -1;
}

void trace(int r, int c) {
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++)
		a[i][j] = 0;

	for (int i = 1; i <= n; i++)
	for (int j = c + 1; j <= m; j++)
		a[i][j] = '+';
	int x = (m / 2 + 1) - (m - c);

	if (x <= 0) {
		for (int j = 1; j <= c; j++)
		for (int i = 1; i <= n; i++) 
			a[i][j] = (i <= n / 2 + 1) ? '-' : '+';
		return;
	}

	for (int i = 1, cur = 1; i <= r; i++) {
		for (int t = 1; t <= x; t++) {
			a[i][cur] = '+';
			cur++;
			if (cur > c)
				cur = 1;
		}

		for (int j = 1; j <= c; j++)
			if (!a[i][j])
				a[i][j] = '-';
	}

	for (int j = 1; j <= c; j++) {
		int cnt = (n / 2 + 1);
		for (int i = 1; i <= r; i++) 
			cnt -= a[i][j] == '-';
		
		for (int i = r + 1; i <= n; i++) {
			if (cnt > 0) {
				a[i][j] = '-';
				cnt--;
			} else
				a[i][j] = '+';
		}
	}
}

void solve() {
	cin >> n >> m;

	int ans = 0;
	int res = 0;
	for (int i = 0; i <= m; i++)
		if (maxi(ans, check(i)))
			res = i;
	cout << ans << "\n";
	trace(ans - res, res);
	for (int i = 1; i <= n; i++, cout << "\n")
	for (int j = 1; j <= m; j++)
		cout << a[i][j];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef ONLINE_JUDGE
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	#endif
	int t; cin >> t;
	while (t--)
		solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1420 KB Output is correct
2 Correct 25 ms 2636 KB Output is correct
3 Correct 25 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1560 KB Output is correct
2 Correct 27 ms 2460 KB Output is correct
3 Correct 22 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 32 ms 1420 KB Output is correct
6 Correct 25 ms 2636 KB Output is correct
7 Correct 25 ms 3028 KB Output is correct
8 Correct 36 ms 1560 KB Output is correct
9 Correct 27 ms 2460 KB Output is correct
10 Correct 22 ms 2132 KB Output is correct
11 Correct 10 ms 592 KB Output is correct
12 Correct 24 ms 2596 KB Output is correct
13 Correct 25 ms 2836 KB Output is correct
14 Correct 17 ms 2332 KB Output is correct
15 Correct 29 ms 3248 KB Output is correct
16 Correct 23 ms 2536 KB Output is correct
17 Correct 12 ms 1876 KB Output is correct