Submission #648169

#TimeUsernameProblemLanguageResultExecution timeMemory
648169ymmRed-blue table (IZhO19_stones)C++17
100 / 100
34 ms9308 KiB
#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();
}
#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...