답안 #1093905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093905 2024-09-28T04:44:36 Z stdfloat Red-blue table (IZhO19_stones) C++17
17 / 100
2000 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define all(v) (v).begin(), (v).end()

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

	int mx = 0;
	for (int mk = 0; mk < 1 << n * m; mk++) {
		vector<vector<int>> a(n, vector<int>(m));
		for (int i = 0; i < n * m; i++)
			a[i / m][i % m] = (mk >> i) & 1;

		int scr = 0;
		for (int i = 0; i < n; i++)
			scr += (count(all(a[i]), 0) > count(all(a[i]), 1));
	
		for (int i = 0; i < m; i++) {
			vector<int> cnt(2);
			for (int j = 0; j < n; j++)
				cnt[a[j][i]]++;

			scr += (cnt[1] > cnt[0]);
		}

		mx = max(mx, scr);
	}

	cout << mx << '\n';
	assert(mx == max(n, m) + (min(n, m) - 1 >> 1));
	for (int mk = 0; mk < 1 << n * m; mk++) {
		vector<vector<int>> a(n, vector<int>(m));
		for (int i = 0; i < n * m; i++)
			a[i / m][i % m] = (mk >> i) & 1;

		int scr = 0;
		for (int i = 0; i < n; i++)
			scr += (count(all(a[i]), 0) > count(all(a[i]), 1));
	
		for (int i = 0; i < m; i++) {
			vector<int> cnt(2);
			for (int j = 0; j < n; j++)
				cnt[a[j][i]]++;

			scr += (cnt[1] > cnt[0]);
		}

		if (scr == mx) {
			for (auto i : a) {
				for (auto j : i)
					cout << (j ? '-' : '+');
				cout << '\n';
			}
			return;
			cout << '\n';
		}
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int T;
	cin >> T;
	while (T--) solve();
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from stones.cpp:1:
stones.cpp: In function 'void solve()':
stones.cpp:34:38: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   34 |  assert(mx == max(n, m) + (min(n, m) - 1 >> 1));
      |                            ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 14 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 14 ms 460 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2068 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 14 ms 460 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -