제출 #910248

#제출 시각아이디문제언어결과실행 시간메모리
910248daoquanglinh2007Red-blue table (IZhO19_stones)C++17
100 / 100
52 ms2388 KiB
#include <bits/stdc++.h>
using namespace std;

#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair

const int NM = 1000;

int T, N, M, ans;
char a[NM+5][NM+5];
priority_queue <pii> Q;
vector <pii> v;

void build(int k, int l){
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= M; j++){
			if (i <= k) a[i][j] = '+'; else a[i][j] = '-';
		}
	while (!Q.empty()) Q.pop();
	for (int i = 1; i <= l; i++) Q.push(mp((N+2)/2-N+k, i));
	for (int i = l+1; i <= N; i++) Q.push(mp(-1, i));
	
	for (int i = 1; i <= k; i++){
		v.clear();
		for (int j = 1; j <= M-(M+2)/2; j++){
			v.push_back(Q.top());
			Q.pop();
		}
		for (pii P : v) a[i][P.se] = '-';
		for (pii P : v){
			Q.push(mp(P.fi-1, P.se));
		}
	}
}

void solve(){
	cin >> N >> M;
	int bestk = -1, bestl = -1;
	for (int k = 0; k <= N; k++){
		int num = k*(M-(M+2)/2), den = (N+2)/2-N+k, l;
		if (den <= 0) l = M; else l = min(num/den, M);
		if (k+l > bestk+bestl){
			bestk = k;
			bestl = l;
		}
	}
	cout << bestk+bestl << '\n';
	build(bestk, bestl);
	
	for (int i = 1; i <= N; i++){
		for (int j = 1; j <= M; j++) cout << a[i][j];
		cout << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> T;
	while (T--){
		solve();
	}
	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...