답안 #972382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972382 2024-04-30T11:35:54 Z colossal_pepe Red-blue table (IZhO19_stones) C++17
11 / 100
519 ms 1552 KB
#include <bits/stdc++.h>
using namespace std;

int t, n, m;

void rotate(vector<vector<bool>> &v) {
	int nv = v.size(), mv = v[0].size();
	vector<vector<bool>> vp(mv, vector<bool>(nv));
	for (int i = 0; i < nv; i++) {
		for (int j = 0; j < mv; j++) {
			vp[j][i] = !v[i][j];
		}
	}
	v = vp;
}

int solve(int nv, int mv, vector<vector<bool>> &v) {
	auto ok = [nv, mv, &v](int save) {
		vector<int> cnt(save, nv);
		priority_queue<pair<int, int>> pq;
		for (int i = 0; i < save; i++) {
			pq.push(make_pair(cnt[i], i));
		}
		int plus = (mv / 2) + (mv % 2) - (mv - save);
		for (int i = 0; i < nv; i++) {
			for (int j = 0; j < mv; j++) {
				v[i][j] = (j >= save);
			}
			for (int _ = 1; _ <= plus; _++) {
				auto [__, j] = pq.top();
				pq.pop();
				v[i][j] = 1;
				pq.push(make_pair(--cnt[j], j));
			}
		}
		bool ret = 1;
		for (int x : cnt) {
			ret &= (x > nv / 2);
		}
		return ret;
	};
	int lo = 0, hi = mv;
	while (hi - lo > 1) {
		int mid = (lo + hi) / 2;
		if (ok(mid)) lo = mid;
		else hi = mid - 1;
	}
	if (ok(hi)) return nv + hi;
	ok(lo);
	return nv + lo;
}

int main() {
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vector<bool>> org(n, vector<bool>(m));
		int goodA = solve(n, m, org);
		vector<vector<bool>> alt(m, vector<bool>(n));
		int goodB = solve(m, n, alt);
		if (goodA < goodB) {
			swap(goodA, goodB);
			rotate(alt);
			swap(alt, org);
		}
		cout << goodA << '\n';
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << (org[i][j] ? '+' : '-');
			}
			cout << '\n';
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 432 KB in the table A+B is not equal to 21
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 309 ms 1476 KB Output is correct
2 Correct 519 ms 1552 KB Output is correct
3 Correct 502 ms 1548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 376 ms 1476 KB in the table A+B is not equal to 46
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -