제출 #340676

#제출 시각아이디문제언어결과실행 시간메모리
340676wwddRed-blue table (IZhO19_stones)C++14
100 / 100
55 ms9196 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
int main() {
	ll N;
	cin >> N;
	while(N--) {
		ll n,m;
		cin >> n >> m;
		pl ha = {0,0},va = {0,0};
		for(int i=0;i<(m/2+1);i++) {
			ll tot = (m-(m/2+1))*(n-i);
			ll ro = (n/2+1)-i;
			ll su = 0;
			if(ro <= 0) {
				su = m;
			} else {
				su = min(tot/ro,m);
			}
			if(su+n-i > ha.second) {
				ha = {i,su+n-i};
			}
		}
		for(int i=0;i<(n/2+1);i++) {
			ll tot = (n-(n/2+1))*(m-i);
			ll ro = (m/2+1)-i;
			ll su = 0;
			if(ro <= 0) {
				su = n;
			} else {
				su = min(tot/ro,n);
			}
			if(su+m-i > ha.second) {
				ha = {i,su+m-i};
			}
		}
		vector<vector<ll> > res;
		ll ans = max(ha.second,va.second);
		if(ha.second > va.second) {
			res.assign(n,vector<ll>(m,1));
			ll st = ha.first;
			for(int i=0;i<st;i++) {
				for(int j=0;j<m;j++) {
					res[i][j] = 0;
				}
			}
			ll ro = (n/2+1)-st;
			ll rot = ro*(ha.second+st-n);
			for(int i=0;i<rot;i++) {
				res[(i%(n-st))+st][i/ro] = 0;
			}
		} else {
			res.assign(n,vector<ll>(m,0));
			ll st = va.first;
			for(int i=0;i<n;i++) {
				for(int j=0;j<st;j++) {
					res[i][j] = 1;
				}
			}
			ll ro = (m/2+1)-st;
			ll rot = ro*(va.second+st-m);
			for(int i=0;i<rot;i++) {
				res[i/ro][(i%(m-st))+st] = 1;
			}
		}
		cout << ans << '\n';
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				cout << (res[i][j]?'+':'-');
			}
			cout << '\n';
		}
	}
}
#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...