Submission #201551

# Submission time Handle Problem Language Result Execution time Memory
201551 2020-02-11T04:03:53 Z my04 Red-blue table (IZhO19_stones) C++17
0 / 100
2000 ms 632 KB
/* 

И пусть меня погубит, то к чему я
Бегу, не жалея ног.
И если мне суждено сгореть на восходе,
Я буду идти вперёд.

*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

const bool dbg_flg = 0;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n' 

const int inf = 1e9 + 7;
const int MAXN = 1e5 + 5;

int n, m;
char x[55][55];
int res;
char y[55][55];

void rec(int v) {
	if (v == n) {
		int a = 0, b = 0;

		for (int i = 1; i <= n; i++) {
			int red = 0;
			int blue = 0;

			for (int j = 1; j <= m; j++) {
				
				if (x[i][j] == '+') red++;
				else blue++;
				
			}

			if (red > blue) a++;
		}

		for (int i = 1; i <= m; i++) {
			int red = 0;
			int blue = 0;

			for (int j = 1; j <= n; j++) {
				if (x[j][i] == '+') red++;
				else blue++;
			}

			if (blue > red) b++;
		}


		if (a + b > res) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					y[i][j] = x[i][j];
				}    
			}

			res = a + b;
		}

		return;
	}


	for (int i = 0; i < (1 << m); i++) {
		
		for (int j = 0; j < m; j++) {
			if (i & (1 << j)) x[v + 1][j + 1] = '+';
			else x[v + 1][j + 1] = '-';			
		}

		rec(v + 1);

	}

}

void solve() {
	cin >> n >> m;

	rec(0);

	cout << res << '\n';

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << y[i][j] << ' ';
		}
		cout << '\n';
	}
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2073 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Wrong answer
2 Halted 0 ms 0 KB -