QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#256853 | #7689. Flipping Cards | Fr1nGeLove | WA | 0ms | 3480kb | C++23 | 953b | 2023-11-18 22:20:47 | 2023-11-18 22:20:48 |
Judging History
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;
}
詳細信息
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'