QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#243950 | #7689. Flipping Cards | haze | TL | 1ms | 3440kb | C++20 | 2.0kb | 2023-11-08 19:36:24 | 2023-11-08 19:36:25 |
Judging History
answer
/*
Author: haze
2023/11/8
19:21
*/
#include <bits/stdc++.h>
#define irep(i, l, r) for(int (i) = (l); (i) <= (r); ++(i))
#define drep(i, r, l) for(int (i) = (r); (i) >= (l); --(i))
#define ll long long
#define LL __int128
using namespace std;
inline ll read() {
char ch = getchar();
ll s = 0;
bool w = 0;
while (!isdigit(ch)) {
if (ch == '-')w = 1;
ch = getchar();
}
while (isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return w ? -s : s;
}
inline char rc() {
char ch = getchar();
while (1) {
if (ch >= '!' && ch <= '~')return ch;
ch = getchar();
}
}
template<class T1, class T2>
T1 min(T1 AA, T2 BB) { return AA > BB ? BB : AA; }
template<class T1, class T2>
T1 max(T1 AA, T2 BB) { return AA < BB ? BB : AA; }
const int itinf = 1e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;
int main() {
int n = read();
vector<array<ll, 2>>a(n);
irep(i, 0, n - 1){
int ai = read(), bi = read();
a[i] = {ai, bi};
}
int l = 0, r = 1e9;
auto check = [&](int x) -> bool{
int goal = (n + 1) >> 1, cnt = 0;
vector<int>f;
for(auto [aa, bb] : a){
if(aa >= x) ++ cnt;
bool f1 = aa >= x, f2 = bb >= x;
if(f1 == f2)f.emplace_back(0);
else if(f2 == 1)f.emplace_back(1);
else f.emplace_back(-1);
}
irep(i, 1, n - 1)f[i] += f[i - 1];
ll minval = 0, ans = 0;
for(int i = 0; i < n; ++ i){
ans = max(ans, f[i] - minval);
minval = min(minval, f[i]);
}
if(cnt + ans >= goal)return true;
return false;
};
while(l < r){
int mid = (l + r) >> 1;
if(check(mid)){
l = mid;
}
else{
r = mid - 1;
}
}
cout << l;
return 0;
}
/*
* 5
3 6
5 2
4 7
6 4
2 8
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3436kb
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: 1ms
memory: 3376kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3388kb
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...