제출 #837956

#제출 시각아이디문제언어결과실행 시간메모리
837956MODDIRed-blue table (IZhO19_stones)C++14
38 / 100
43 ms1824 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
// 3 3
// -++
// +-+
// -++
// wlog N > M
// every row will have N/2+1 red stones
// then make rows
int main(){
	int t;
	cin>>t;
	while(t--){
		int n, m;
		cin>>n>>m;
		int ans = 0;
		char mat[n][m];
		if(n >= m){
			int minus[m];
			memset(minus, 0, sizeof minus);
			for(int i = 0; i < n; i++){
				int need = m/2 + 1;
				for(int j = 0; j < m; j++){
					if(minus[j] < n/2+1 && (m-j-1) >= need){
						minus[j]++;
						mat[i][j] = '-';
					}
					else{
						mat[i][j] = '+';
						need--;
					}
				}
				ans++;
			}
			for(int i = 0; i < m; i++){
				if(minus[i] >= n/2+1)	ans++;
			}
			int to_break = 0, bgain = 0;
			for(int b = 1; b <= n; b++){
				int gain = 0;
				for(int j = 0; j < m; j++){
					if(minus[j] >= n/2+1)	continue;
					if(minus[j] + b >= n/2+1)	gain++;
				}
				if(bgain < gain - b){
					bgain = gain-b;
					to_break = b;
				}
			}
			ans += bgain;
			for(int i = 0; i < to_break; i++){
				for(int j = 0; j < m; j++){
					mat[i][j]='-';
				}
			}
			cout<<ans<<"\n";
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++)
					cout<<mat[i][j];
				cout<<endl;
			}
		}
		else{
			int plus[n];
			memset(plus, 0, sizeof plus);
			for(int j = 0; j < m; j++){
				int need = n/2 + 1;
				for(int i = 0; i < n; i++){
					if(plus[i] < m/2+1 && (n - i - 1) >= need){
						mat[i][j] = '+';
						plus[i]++;
					}
					else{
						mat[i][j] = '-';
						need--;
					}
				}
				ans++;
			}
			for(int i = 0; i < n; i++)
				if(plus[i] >= m / 2 + 1)	ans++;
			
			int to_break = 0, bgain = 0;
			for(int b = 1; b <= m; b++){
				int gain = 0;
				for(int i = 0; i < n; i++){
					if(plus[i] >= m/2+1)	continue;
					else if(plus[i] + b >= m/2+1)	gain++;
				}
				if(bgain < gain-b){
					bgain = gain-b;
					to_break = b;
				}
			}
			ans += bgain;
			for(int j = 0; j < to_break; j++){
				for(int i = 0; i < n; i++)
					mat[i][j] = '+';
			}
			cout<<ans<<"\n";
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++)
					cout<<mat[i][j];
				cout<<endl;
			}
		}
	}
	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...