Submission #859992

#TimeUsernameProblemLanguageResultExecution timeMemory
859992Halym2007Red-blue table (IZhO19_stones)C++11
100 / 100
76 ms3156 KiB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int N = 1e3 + 5;
priority_queue <pair <int, int>> q; 
char jog[N][N], jog1[N][N];

int main() {
//	freopen ("input.txt", "r", stdin);
	int t;
	cin >> t;
	while ( t-- ) {
		int n, m;
		cin >> n >> m;
//		cout << "test cases : " << n << " " << m << endl;
		bool tr = 0;
		if (n < m) {
			swap (n, m);
			tr = 1;
		}
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				jog[i][j] = '+';
			}
		}
		int a = n / 2 + 1;
		int b = (m - 1) / 2;
		int ans = n + ((n * b) / a);
		for (int i = 1; i <= n; ++i) {
			if (b) q.push({b, i});
		}
		for (int i = 1; i <= ans; ++i) { 
			for (int j = 1; j <= a; ++j) { 
				if (q.empty()) break;
				pair <int, int> x = q.top();
				q.pop();
				jog[x.ss][i] = '-';
				if (x.ff > 1) {
					q.push ({x.ff - 1, x.ss});
				} 
			}
			if (q.empty()) break;
		}
		if (tr) { 
			for (int i = 1; i <= n; ++i) {
				for (int j = m; j > 0; j--) {
					if (jog[i][j] == '-') jog[i][j] = '+';
					else jog[i][j] = '-';
				}
			}
			int l1 = 1, r1 = m;
			for (int i = 1; i <= m; ++i) {
				for (int j = 1; j <= n; ++j) {
					jog1[i][j] = jog[l1][r1];
					l1++;
				}
				l1 = 1;
				r1--;
				cout << endl;
			}
			if (tr) swap (n, m);
		}
		else {
			for (int i = 1; i <= n; ++i) {
				for (int j = 1; j <= m; ++j) {
					jog1[i][j] = jog[i][j];
				}
			}
		}
		//
//		int row = 0, column = 0;
//		for (int i = 1; i <= n; ++i) {
//			int x = 0;
//			for (int j = 1; j <= m; ++j) {
//				if (jog1[i][j] == '+') x++;
//				else x--;
//			}
//			if (x > 0) row++;
//		}
//		for (int i = 1; i <= m; i++) {
//			int x = 0;
//			for (int j = 1; j <= n; ++j) {
//				if (jog1[j][i] == '-') x++;
//				else x--;
//			}
//			if (x > 0) column++;
//		}
//		int tt = row + column;
		//
		cout << ans << endl;
//		if (ans != tt) {
//			cout << "men : " << row << " " << column << " " << tt << "\n";
//		}
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				cout << jog1[i][j];
			}
			cout << endl;
		}
	} 
}
#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...