답안 #648169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648169 2022-10-05T15:58:32 Z ymm Red-blue table (IZhO19_stones) C++17
100 / 100
34 ms 9308 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 2048;
int ans[N][N];
int n, m;

bool test(int x, int y)
{
	int have = ((m-1)/2) * (n-x) + (m-y)*x;
	int want = (n/2+1) * (m-y);
	return have >= want;
}

void make(int x, int y)
{
	Loop (i,0,x) Loop (j,0,m)
		ans[i][j] = 0;
	Loop (i,0,n) Loop (j,0,y)
		ans[i][j] = 1;
	int need = m/2+1 - y;
	int pos = 0;
	Loop (i,0,n-x) {
		Loop (j,0,m-y)
			ans[i+x][j+y] = 0;
		Loop (j,pos,pos+need)
			ans[i+x][j%(m-y)+y] = 1;
		pos += need;
	}
}

void solve()
{
	cin >> n >> m;
	pii ans = {-1, -1};
	if      (test(0, 1))
		ans = {0, 1};
	else if (test(1, 0))
		ans = {1, 0};
	else if (test(0, 2))
		ans = {0, 2};
	else if (test(0, 2))
		ans = {0, 2};
	else if (test(1, 1))
		ans = {1, 1};
	else if (test(2, 0))
		ans = {2, 0};
	else if (test(0, 3))
		ans = {0, 3};
	else if (test(1, 2))
		ans = {1, 2};
	else if (test(2, 1))
		ans = {2, 1};
	else if (test(3, 0))
		ans = {3, 0};
	else if (test(2, 2))
		ans = {2, 2};
	assert(ans.first != -1);
	make(ans.first, ans.second);
	cout << n+m - ans.first - ans.second << '\n';
	Loop (i,0,n) {
		Loop (j,0,m)
			cout << "-+"[::ans[i][j]];
		cout << '\n';
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
		solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1748 KB Output is correct
2 Correct 23 ms 7164 KB Output is correct
3 Correct 25 ms 8664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1820 KB Output is correct
2 Correct 22 ms 6784 KB Output is correct
3 Correct 24 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 25 ms 1748 KB Output is correct
6 Correct 23 ms 7164 KB Output is correct
7 Correct 25 ms 8664 KB Output is correct
8 Correct 33 ms 1820 KB Output is correct
9 Correct 22 ms 6784 KB Output is correct
10 Correct 24 ms 3284 KB Output is correct
11 Correct 7 ms 560 KB Output is correct
12 Correct 20 ms 4252 KB Output is correct
13 Correct 25 ms 4656 KB Output is correct
14 Correct 16 ms 3996 KB Output is correct
15 Correct 34 ms 9308 KB Output is correct
16 Correct 21 ms 7372 KB Output is correct
17 Correct 10 ms 3284 KB Output is correct