Submission #1230748

#TimeUsernameProblemLanguageResultExecution timeMemory
1230748altern23Red-blue table (IZhO19_stones)C++20
100 / 100
36 ms2372 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pii pair<ll, ll>
#define fi first
#define sec second
#define ld long double

const int MAXN = 1e5;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);	
	int tc = 1;	
	cin >> tc;
	for(;tc--;){
		ll N, M; cin >> N >> M;
		vector<ll> cur(M + 5, N), cur2(N + 5, M);
		ll ans = M;
		ll rows = M, pt = 0;
		for(int i = 1; i <= N; i++){
			sort(cur.begin() + 1, cur.begin() + 1 + M, greater<ll>());
			for(int j = 1; j <= M / 2 + 1; j++){
				cur[j]--;
				if(cur[j] == N / 2) rows--;
			}
			if(ans < rows + i){
				ans = rows + i;
				pt = i;
			}
		}
		
		ll anss = N;
		ll col = N, pt1 = 0;
		for(int i = 1; i <= M; i++){
			sort(cur2.begin() + 1, cur2.begin() + 1 + N, greater<ll>());
			for(int j = 1; j <= N / 2 + 1; j++){
				cur2[j]--;
				if(cur2[j] == M / 2) col--;
			}
			if(anss < col + i){
				anss = col + i;
				pt1 = i;
			}
		}
		
		vector<vector<char>> grid(N + 5, vector<char>(M + 5));
		
		if(ans > anss){
			for(int i = 1; i <= N; i++){
				for(int j = 1; j <= M; j++) grid[i][j] = '-';
			}
		
			vector<pii> now;
			for(int i = 1; i <= M; i++) now.push_back({N, i});
			for(int i = 1; i <= pt; i++){
				sort(now.begin(), now.end(), greater<pii>());
				for(int j = 0; j < M / 2 + 1; j++){
					grid[i][now[j].sec] = '+';
					now[j].fi--;
				}
			}
			
			cout << ans << "\n";
			for(int i = 1; i <= N; i++){
				for(int j = 1; j <= M; j++) cout << grid[i][j];
				cout << "\n";
			}
		}
		else{
			for(int i = 1; i <= N; i++){
				for(int j = 1; j <= M; j++) grid[i][j] = '+';
			}
			
			vector<pii> now;
			for(int i = 1; i <= N; i++) now.push_back({M, i});
			for(int i = 1; i <= pt1; i++){
				sort(now.begin(), now.end(), greater<pii>());
				for(int j = 0; j < N / 2 + 1; j++){
					grid[now[j].sec][i] = '-';
					now[j].fi--;
				}
			}
			
			cout << anss << "\n";
			for(int i = 1; i <= N; i++){
				for(int j = 1; j <= M; j++) cout << grid[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...