QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725349 | #7689. Flipping Cards | garhlz | WA | 4ms | 9768kb | C++17 | 1.4kb | 2024-11-08 17:13:47 | 2024-11-08 17:13:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5+10;
int a[N],b[N],tmp[N<<1],f[N];
int n;
int chk(int x){
int xi = 0,da = 0;
for(int i = 1;i<=n;i++){
if(a[i]<x)xi++;
else if(a[i]>x)da++;
}
if(xi==da && xi==n/2){
return 1;
}
for(int i = 1;i<=n;i++){
if(a[i]<x && b[i]>x)f[i] = 1;
else if(a[i]>x && b[i]<x)f[i] = -1;
else f[i] = 0;
}
int l = 0;
int d = xi - da;
d/=2;//需要的数字
map<int,int> mp;
int now = 0;
mp[0] = 1;//第零位
for(int i = 1;i<=n;i++){
now+=f[i];
if(mp[now - d])return 1;
mp[now] = 1;
}
return 0;
}
void solve(){
cin>>n;
int ind = 0;
for(int i = 1;i<=n;i++){
cin>>a[i]>>b[i];
tmp[++ind] = a[i],tmp[++ind] = b[i];
}
if(n==1){
cout<<max(a[1],b[1])<<'\n';
return;
}
sort(tmp+1,tmp+1+2*n);
int l = 0,r = n*2+1;
int ans = 0;
while(l<r){
int m = (l+r)/2;
if(chk(tmp[m])){
l = m+1;
}
else r = m-1;
}
if(chk(l))cout<<tmp[l]<<'\n';
else cout<<tmp[l-1]<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
// cin>>t;
while(t--)
solve();
return 0;
}
/*
5
3 6
5 2
4 7
6 4
2 8
5
1 2
2 3
3 4
4 5
5 6
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9664kb
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: 9700kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9768kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: 0
Accepted
time: 0ms
memory: 9712kb
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: 0
Accepted
time: 1ms
memory: 9692kb
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...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9696kb
input:
103 66 46 41 70 52 76 26 5 54 2 78 21 22 39 100 15 73 94 56 7 45 72 76 80 6 67 12 8 86 53 26 1 5 57 90 44 81 85 2 70 32 79 95 42 97 37 87 93 2 21 21 42 29 25 61 35 98 99 33 46 51 10 45 56 40 75 71 25 79 37 75 10 34 98 1 22 40 12 14 81 83 29 51 12 37 96 74 11 30 49 39 34 68 68 36 17 3 55 41 32 22 92 ...
output:
55
result:
ok 1 number(s): "55"
Test #7:
score: -100
Wrong Answer
time: 4ms
memory: 9696kb
input:
5555 884376710 45124731 564350738 110566376 82266416 71890085 742302826 424812817 441684523 786251012 1208704 118200627 206028578 736388312 179371956 412238226 562783304 721943945 855108903 710808533 969831121 89689888 833625410 9559177 39704951 153974475 778740527 562223006 103796470 968790365 2050...
output:
520792102
result:
wrong answer 1st numbers differ - expected: '520583648', found: '520792102'