QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#255122 | #7689. Flipping Cards | GCnoodlesbot# | WA | 0ms | 3816kb | C++20 | 1.1kb | 2023-11-18 14:50:57 | 2023-11-18 14:50:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
auto check = [&](int x) {
vector<int> A(n + 2), B(n + 2), C(n + 2);
for (int i = 1; i <= n; i++) {
if (a[i] >= x) A[i] = A[i - 1] + 1;
else A[i] = A[i - 1];
if (b[i] >= x) B[i] = B[i - 1] + 1;
else B[i] = B[i - 1];
}
for (int i = n; i >= 1; i--) {
if (a[i] >= x) C[i] = C[i + 1] + 1;
else C[i] = C[i + 1];
}
int maxv = -1E9, res = A[n];
for (int i = 1; i <= n; i++) {
res = max(res, B[i] + maxv + C[i + 1]);
maxv = max(maxv, A[i] - B[i - 1]);
}
return res >= (n + 1) / 2;
};
int l = 1, r = 1e9;
while (l < r) {
int mid = (l + r + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << r << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3484kb
input:
5 3 6 5 2 4 7 6 4 2 8
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3816kb
input:
1 212055293 384338286
output:
212055293
result:
wrong answer 1st numbers differ - expected: '384338286', found: '212055293'