QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#485084 | #7689. Flipping Cards | yaoy | WA | 0ms | 3876kb | C++17 | 1.5kb | 2024-07-20 11:42:55 | 2024-07-20 11:42:55 |
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<std::array<int, 2>> card(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
std::cin >> card[i][j];
}
}
auto check = [&](int x) -> bool {
std::array<int, 3> dp {};
for (int i = 0; i < n; i++) {
std::array<int, 3> ndp {};
for (int s = 0; s < 3; s++) {
if (s == 2) {
ndp[2] = std::max(ndp[2], dp[2] + (card[i][0] >= x));
} else if (s == 1) {
ndp[1] = std::max(ndp[1], dp[1] + (card[i][1] >= x));
ndp[2] = std::max(ndp[2], dp[1] + (card[i][0] >= x));
} else {
ndp[0] = std::max(ndp[0], dp[0] + (card[i][0] >= x));
ndp[1] = std::max(ndp[1], dp[0] + (card[i][1] >= x));
}
}
dp = std::move(ndp);
}
int res = *std::max_element(dp.begin(), dp.end());
return res >= (n + 1) / 2;
};
int lo = 1, hi = 10, ans = -1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (check(mid)) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 3628kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3876kb
input:
1 212055293 384338286
output:
10
result:
wrong answer 1st numbers differ - expected: '384338286', found: '10'