QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#237191 | #7689. Flipping Cards | ucup-team1055# | WA | 0ms | 3808kb | C++20 | 1.2kb | 2023-11-04 13:26:26 | 2023-11-04 13:26:26 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class T>
bool chmin(T &a, T b) {
if(a <= b) return false;
a = b;
return true;
}
template<class T>
bool chmax(T &a, T b) {
if(a >= b) return false;
a = b;
return true;
}
using namespace std;
const int iinf = 1'000'00'010;
int main() {
int n; cin >> n;
vector<int> a(n), b(n);
rep(i,0,n) cin >> a[i] >> b[i];
int le = 1, ri = iinf;
while (ri - le > 1){
int md = (le + ri) / 2;
vector<int> p(n,0);
rep(i,0,n){
if (a[i] >= md) p[i]--;
if (b[i] >= md) p[i]++;
}
vector<int> dp(n+1,-iinf);
int ans = 0;
rep(i,0,n){
chmax(dp[i+1],p[i]);
chmax(dp[i+1],p[i]+dp[i]);
chmax(ans,dp[i+1]);
}
rep(i,0,n) if (a[i] >= md) ans++;
if (ans >= (n/2+1)) le = md;
else ri = md;
}
cout << le << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3472kb
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: 3808kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3584kb
input:
1 212055293 384338286
output:
100000009
result:
wrong answer 1st numbers differ - expected: '384338286', found: '100000009'