QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#662414 | #7689. Flipping Cards | jiangtao | WA | 0ms | 3624kb | C++20 | 1.9kb | 2024-10-20 23:55:26 | 2024-10-20 23:55:26 |
Judging History
answer
// Problem: M. Flipping Cards
// Contest: Codeforces - 2023 China Collegiate Programming Contest (CCPC) Guilin Onsite (The 2nd Universal Cup. Stage 8: Guilin)
// URL: https://codeforces.com/gym/104768/problem/M
// Memory Limit: 1024 MB
// Time Limit: 2500 ms
// Begin:2024-10-20 17:07:06
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5, M = 1e9 + 7, mod = 998244353;
#define YES {cout << "Yes" << endl; return ;}
#define NO {cout << "No" << endl; return ;}
void solve(){
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
vector<int> now;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i], now.push_back(a[i]);
auto check = [&](int mid){
vector<int> s(n + 1);
int res = INT_MIN, l = -1, r = -1;
int minn = 0, id = -1;
for (int i = 1; i <= n; i++){
if (a[i] < mid && b[i] < mid) s[i] = 0;
else if (a[i] >= mid && b[i] >= mid) s[i] = 0;
else if (a[i] < mid && b[i] >= mid) s[i] = 1;
else if (a[i] >= mid && b[i] < mid) s[i] = -1;
s[i] += s[i - 1];
if (res < s[i] - minn) {res = s[i] - minn; l = id; r = i;}
if (s[i] < minn) {minn = s[i]; id = i;}
}
int cnt = 0;
// cout << mid << " " << res << "\n";
for (int i = 1; i <= n; i++){
int now = a[i];
if (res >= 0 && i >= l && i <= r){
now = b[i];
}
if (now >= mid) cnt++;
}
if (n / 2 + 1 <= cnt) return true;
return false;
};
int l = 1, r = 1e9;
while (l < r){
int mid = (l + r + 1) >> 1;
if (check(mid)){
l = mid;
}else{
r = mid - 1;
}
}
cout << l << "\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int ___ = 1;
// cin >> ___;
while (___--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 3524kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3536kb
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:
507850962
result:
wrong answer 1st numbers differ - expected: '528957505', found: '507850962'