Submission #1287515

#TimeUsernameProblemLanguageResultExecution timeMemory
1287515azamuraiRed-blue table (IZhO19_stones)C++20
27 / 100
9 ms4416 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define Sz(x) (int)x.size()
#define mp make_pair

typedef long long ll;

const int N = 1005;
int n, m;
char a[N][N];

int calc() {
	int res = 0;
	for (int i = 1; i <= n; i++) {
		int blue = 0, red = 0;
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == '-') blue++;
			else red++;
		}
		if (red > blue) res++;
	}
	for (int j = 1; j <= m; j++) {
		int blue = 0, red = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i][j] == '-') blue++;
			else red++;
		}
		if (blue > red) res++;
	}
	return res;
}

void solve() {
	cin >> n >> m;
	if (min(n, m) == 1) {
		if (n == 1) {
			for (int j = 1; j <= m; j++) {
				a[1][j] = '-';
			}
		}
		else {
			for (int i = 1; i <= n; i++) {
				a[i][1] = '+';
			}
		}
	}
	else if (min(n, m) == 2) {
		if (n == 2) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					a[i][j] = '-';
				}
			}
		}
		else {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					a[i][j] = '+';
				}
			}
		}
	}
	else if (min(n,m) == 3) {
		if (n == 3) {
			for (int i = 1; i <= 2; i++) {
				for (int j = 1; j <= m; j++) {
					a[i][j] = '-';
				}
			}
			for (int j = 1; j <= m; j++) {
				a[3][j] = '+';
			}
		}
		else {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= 2; j++) {
					a[i][j] = '+';
				}
			}
			for (int i = 1; i <= n; i++) {
				a[i][3] = '-';
			}
		}
	}
	else if (min(n, m) == 4) {
		if (n == 4) {
			for (int i = 1; i <= 3; i++) {
				for (int j = 1; j <= m; j++) {
					a[i][j] = '-';
				}
			}
			for (int j = 1; j <= m; j++) {
				a[4][j] = '+';
			}
		}
		else {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= 3; j++) {
					a[i][j] = '+';
				}
			}
			for (int i = 1; i <= n; i++) {
				a[i][4] = '-';
			}
		}
	}
	else {
		if (n == 5) {
			for (int i = 1; i <= 3; i++) {
				for (int j = 1; j <= m; j++) {
					a[i][j] = '-';
				}
			}
			for (int j = 1; j <= m; j++) {
				a[4][j] = a[5][j] = '+';
			}
		}
		else {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= 3; j++) {
					a[i][j] = '+';
				}
			}
			for (int i = 1; i <= n; i++) {
				a[i][4] = a[i][5] = '-';
			}
		}
	}
	cout << calc() << '\n';
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << a[i][j];
		}
		cout << '\n';
	}
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

	int t = 1;
	cin >> t;
	while ( t-- ) {
		solve();
		//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...