제출 #155475

#제출 시각아이디문제언어결과실행 시간메모리
155475qkxwsmRed-blue table (IZhO19_stones)C++14
100 / 100
41 ms1528 KiB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 1013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int TC;
int N, M;
int A, B;
bitset<MAXN> ans[MAXN];
deque<pii> rem;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> TC;
	while(TC--)
	{
		FOR(i, 0, N)
		{
			FOR(j, 0, M)
			{
				ans[i][j] = false;
			}
		}
		rem.clear();
		cin >> N >> M;
		A = 0; B = 0;
		FOR(i, 0, N + 1)
		{
			//say there are i rows that have more +s than -s.
			//then there are i rows with (M / 2 + 1) +s, N - i rows with 0 +s
			int lo = 0, hi = M;
			while(hi > lo)
			{
				int mid = (hi + lo + 1) >> 1; //can we get mid columns with a majority of -s?
				int tot = (M / 2 + 1) * i;
				FOR(j, 0, M - mid)
				{
					tot -= i;
				}
				FOR(j, 0, mid)
				{
					tot -= ((N - 1) / 2);
				}
				if (tot <= 0) lo = mid;
				else hi = mid - 1;
				//try checking mid
			}
			if (lo + i > A + B)
			{
				A = i;
				B = lo;
			}
		}
		cout << A + B << '\n';
		//now actually construct the grid!
		FOR(i, 0, A)
		{
			FOR(j, B, M)
			{
				ans[i][j] = true;
			}
			rem.PB({i, (M / 2 + 1) - (M - B)});
		}
		//now you just need to do the remaining stuff!
		FOR(i, 0, B)
		{
			FOR(j, 0, (N - 1) / 2)
			{
				if (rem.back().se <= 0) break;
				pii p = rem.back(); rem.pop_back();
				p.se--;
				ans[p.fi][i] = true;
				rem.push_front(p);
			}
		}
		//for the remaining columns
		FOR(i, 0, N)
		{
			FOR(j, 0, M)
			{
				cout << (ans[i][j] ? '+' : '-');
			}
			cout << '\n';
		}
	}
	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...