Submission #855870

# Submission time Handle Problem Language Result Execution time Memory
855870 2023-10-02T05:44:21 Z Halym2007 Red-blue table (IZhO19_stones) C++11
17 / 100
8 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
vector <pair <int, int>> v;
int git, n, m, jogap;
char vis[5][5], jog[5][5];

void solve (int x) {
	if (x == git + 1) {
		int ans = 0;
		for (int i = 1; i <= n; ++i) {
			int r = 0;
			for (int j = 1; j <= m; ++j) {
				if (vis[i][j] == '+') {
					r++;
				}
				else r--;
			}
			if (r > 0) ans++; 
		}
		for (int i = 1; i <= m; ++i) {
			int b = 0;
			for (int j = 1; j <= n; ++j) {
				if (vis[j][i] == '-') b++;
				else b--;
			}
			if (b > 0) ans++;
		}
		if (jogap < ans) {
			jogap = ans;
			for (int i = 1; i <= n; ++i) {
				for (int j = 1; j <= m; ++j) {
					jog[i][j] = vis[i][j];
				}
			}
		}
		return;
	}
	for (int i = 0; i < 2; ++i) {
		char c;
		if (!i) c = '-';
		else c = '+';
		vis[v[x].first][v[x].second] = c;
		solve (x + 1); 
	}
}



int main () {
//	freopen("input.txt", "r", stdin);
	int t;
	cin >> t;
	while ( t-- ) {
		cin >> n >> m;
		git = n * m;
		v.clear();
		jogap = 0;
		v.push_back ({0, 0});
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				v.push_back ({i, j});
			}
		}
		solve (1);
//		cout << "input : " << n << " " << m << endl;
		cout << jogap << "\n";
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				cout << jog[i][j];
			}
			cout << "\n";
		}
//		cout << endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 8 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 8 ms 348 KB Output is correct
3 Runtime error 0 ms 344 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 8 ms 348 KB Output is correct
3 Runtime error 0 ms 344 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -