QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#279437 | #7689. Flipping Cards | abcjjt | WA | 0ms | 3852kb | C++14 | 1.3kb | 2023-12-08 18:29:54 | 2023-12-08 18:29:54 |
Judging History
answer
//
// Created by abc on 23-12-6.
//
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n; cin >> n;
using P = pair<int, int>;
vector<P> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
auto c = a;
sort(c.begin() + 1, c.end());
int left = c[(n + 1) / 2].first, right = 1e10;
auto check = [&](int mid) -> bool {
if (mid <= c[(n + 1) / 2].first) return true;
vector<int> b(n + 1, 0);
int ans = 0;
for (int i = 1; i <= n; i++) {
if (a[i].first >= mid and a[i].second < mid) b[i] = -1;
else if (a[i].first < mid and a[i].second >= mid) b[i] = 1;
else if (a[i].first >= mid and a[i].second >= mid) ans++;
else if (a[i].first < mid and a[i].second < mid) ans--;
}
int res = 0;
for (int i = 1, cnt = 0; i <= n; i++) {
cnt = max(0ll, cnt + b[i]);
res = max(res, cnt);
}
// cout << ans + res << "\n";
return ans + res >= (n & 1);
};
// cout << check(2);
while (left <= right) {
int mid = left + right >> 1;
if (check(mid)) left = mid + 1;
else right = mid - 1;
}
cout << right << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 3852kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3812kb
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:
481980673
result:
wrong answer 1st numbers differ - expected: '528957505', found: '481980673'