QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#256853#7689. Flipping CardsFr1nGeLoveWA 0ms3480kbC++23953b2023-11-18 22:20:472023-11-18 22:20:48

Judging History

你现在查看的是最新测评结果

  • [2023-11-18 22:20:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3480kb
  • [2023-11-18 22:20:47]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

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

	int n;
	std::cin >> n;

	std::vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		std::cin >> a[i] >> b[i];
	}

	auto check = [&](int x) {
		std::vector<int> pre1(n + 1), pre2(n + 1), suf(n + 2);
		for (int i = 0; i < n; i++) {
			pre1[i + 1] = pre1[i] + (a[i] >= x);
			pre2[i + 1] = pre2[i] + (b[i] >= x);
		}
		for (int i = n; i >= 1; i--) {
			suf[i] = suf[i + 1] + (a[i - 1] >= x);
		}

		int res = 0, ans = 0;
		for (int i = 1; i <= n; i++) {
			res = std::max(res, pre1[i - 1] - pre2[i - 1]);
			ans = std::max(ans, res + suf[i + 1] + pre2[i]);
		}

		return ans >= (n + 1) / 2;
	};
	int lo = 0, hi = int(1E9);
	while (hi - lo != 1) {
		int m = (lo + hi) / 2;
		if (check(m)) {
			lo = m;
		} else {
			hi = m;
		}
	}

	check(6);
	std::cout << lo << "\n";

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3372kb

input:

5
3 6
5 2
4 7
6 4
2 8

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3480kb

input:

1
2 1

output:

1

result:

wrong answer 1st numbers differ - expected: '2', found: '1'