QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#543024 | #7689. Flipping Cards | mhw# | TL | 1ms | 3824kb | C++23 | 1.3kb | 2024-09-01 12:53:14 | 2024-09-01 12:53:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
void solve() {
int n;
cin >> n;
vector<pair<int, int>> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
auto check = [&](int x) -> bool {
vector<int> b(n + 1);
i64 ans = 0;
for (int i = 1; i <= n; i++) {
if (a[i].first >= x) ans++;
if (a[i].first >= x && a[i].second < x) b[i] = -1;
else if (a[i].first < x && a[i].second >= x) b[i] = 1;
}
vector<array<int, 2>> dp(n + 1);
dp[0][0] = -1;
int res = 0;
for (int i = 1; i <= n; i++) {
if (dp[i - 1][0] > 0) {
dp[i][0] = dp[i - 1][0] + b[i];
dp[i][1] = 1;
} else {
dp[i][0] = b[i];
dp[i][1] = 0;
}
res = max(res, dp[i][0]);
}
return ans + res >= (n + 1) / 2;
};
int l = 0, r = 1e9;
while (l < r) {
int mid = (l + r) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3824kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
99 749159996 323524232 125448341 365892333 481980673 143665393 394405973 44741918 687549448 513811513 287088118 385131171 11865696 666468353 449920567 373650719 671547289 116780561 41003675 671513243 351534153 507850962 374160874 985661954 222519431 600582098 987220654 704142246 856147059 37783620 1...
output:
528957505
result:
ok 1 number(s): "528957505"
Test #5:
score: -100
Time Limit Exceeded
input:
101 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...