QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641383 | #7689. Flipping Cards | ucup-team2526 | WA | 1ms | 5640kb | C++20 | 2.2kb | 2024-10-14 20:16:51 | 2024-10-14 20:16:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
std::cout << std::endl;
}
template<class T, class... Ts>
void err(T arg, Ts &... args) {
std::cout << fixed << setprecision(10) << arg << ' ';
err(args...);
}
const int maxn = 3e5 + 5;
int a[maxn],b[maxn];
int n;
int check(int x) {
vector<int> val(n + 5);
vector<int> dp(n + 5);
int mi = 0,mx = 0,cnt1 = 0,cnt2 = 0;
for (int i = 1;i <= n;i++) {
if (a[i] <= x && b[i] <= x) {
val[i] = 0;
mi++,mx++;
}
else if (a[i] <= x && b[i] > x) {
val[i] = -1;
cnt1++;
}
else if (a[i] > x && b[i] <= x) {
val[i] = 1;
cnt2++;
}
}
int res = 0,now = 0;
for (int i = 1;i <= n;i++) {
if (dp[i - 1] + val[i] > val[i]) {
dp[i] = dp[i - 1] + val[i];
if (val[i] == -1) now++;
}
else {
dp[i] = val[i];
now = 0;
}
if (dp[i] == -1) dp[i] = 0,now = 0;
res = max(res,dp[i] + cnt1 - now);
}
mx += res;
res = 0,now = 0;
for (int i = 1;i <= n;i++) {
val[i] = -val[i];
dp[i] = 0;
}
swap(cnt1,cnt2);
for (int i = 1;i <= n;i++) {
if (dp[i - 1] + val[i] >= val[i]) {
dp[i] = dp[i - 1] + val[i];
if (val[i] == -1) now++;
}
else {
dp[i] = val[i];
now = 0;
}
if (dp[i] == -1) {
dp[i] = 0;
now = 0;
}
res = max(res,dp[i] + now - cnt2);
}
mi -= res;
if (n / 2 + 1 >= mi && n / 2 + 1 <= mx) return 1;
else if (n / 2 + 1 < mi) {
return 2;
}
else if (n / 2 + 1 > mx) {
return 3;
}
}
void GENSHEN_START() {
cin >> n;
vector<int>c;
for (int i = 1;i <= n;i++) {
cin >> a[i] >> b[i];
c.push_back(a[i]);
c.push_back(a[i]);
}
sort(c.begin(),c.end());
int len = c.size();
int l = 0,r = len - 1;
int ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(c[mid]) == 1) {
l = mid + 1;
ans = max(ans,c[mid]);
}
else if (check(c[mid]) == 2) r = mid - 1;
else if (check(c[mid]) == 3) l = mid + 1;
}
cout << ans;
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
int T = 1;
//cin >> T;
while (T--) GENSHEN_START();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5640kb
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: 5632kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5588kb
input:
1 212055293 384338286
output:
212055293
result:
wrong answer 1st numbers differ - expected: '384338286', found: '212055293'