QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#241976 | #7689. Flipping Cards | muxiuyulin# | TL | 9ms | 7884kb | C++20 | 2.5kb | 2023-11-06 20:33:37 | 2023-11-06 20:33:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=(int)a,i##i=(int)b;i<=i##i;i++)
#define per(i,a,b) for(int i=(int)a,i##i=(int)b;i>=i##i;i--)
mt19937_64 rnd(random_device{}());
#define int ll
typedef pair<int,int> pii;
const int N=400010;
const int mod=998244353;
int n,a[N],b[N],t[N];
int check(int x){
for(int i=1;i<=n;i++){
if(a[i]>=x&&b[i]>=x) t[i]=0;
if(a[i]>=x&&b[i]<x) t[i]=-1;
if(a[i]<x&&b[i]>=x) t[i]=1;
if(a[i]<x&&b[i]<x) t[i]=0;
//cout<<t[i]<<" \n"[i==n];
t[i]+=t[i-1];
//cout<<t[i]<<" \n"[i==n];
}
int l=0,r=0,sum=0;
int mi=0,pos=0;
for(int i=1;i<=n;i++){
int x=t[i]-mi;
if(x>=sum){
sum=x;
l=pos+1;
r=i;
}
if(t[i]<=mi){
mi=t[i];
pos=i;
}
}
if(sum<=0) l=r=0;
vector<int> ans;
//cout<<l<<" "<<r<<" "<<sum<<endl;
for(int i=1;i<=n;i++){
if(i>=l&&i<=r) ans.push_back(b[i]);
else ans.push_back(a[i]);
}
sort(ans.begin(),ans.end());
//for(auto t:ans) cout<<t<<" "; cout<<endl;
return ans[n/2]>=x;
}
int fun(){
int mx=0;
vector<int> ans;
for(int i=1;i<=n;i++) ans.push_back(a[i]);
sort(ans.begin(),ans.end());
mx=max(mx,ans[n/2]);
for(int l=1;l<=n;l++){
for(int r=l;r<=n;r++){
for(int k=l;k<=r;k++) swap(a[k],b[k]);
ans.clear();
for(int k=1;k<=n;k++) ans.push_back(a[k]);
sort(ans.begin(),ans.end());
mx=max(mx,ans[n/2]);
// if(l==1&&r==6||l==1&&r==3){
// cout<<l<<" "<<r<<endl;
// for(auto t:ans) cout<<t<<" ";
// cout<<endl;
// }
for(int k=l;k<=r;k++) swap(a[k],b[k]);
}
}
return mx;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
fun();
check(53);
int l=1,r=1e9;
while(l<r){
int mid=(l+r+1)>>1;
//cout<<l<<" "<<r<<" "<<mid<<" "<<check(mid)<<endl;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
// while(1){
// n=rnd()%10;
// if(n%2==0) n++;
// for(int i=1;i<=n;i++) a[i]=rnd()%100,b[i]=rnd()%100;
// int l=1,r=1e9;
// while(l<r){
// int mid=(l+r+1)>>1;
// if(check(mid)) l=mid;
// else r=mid-1;
// }
// int nl=fun();
// if(l!=nl){
// cout<<l<<" "<<nl<<endl;
// cout<<n<<endl;
// for(int i=1;i<=n;i++) cout<<a[i]<<" "<<b[i]<<endl;
// return ;
// }
// }
}
signed main(){
IOS;
int _=1;
//cin>>_;
while(_--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7632kb
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: 7636kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7884kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: 0
Accepted
time: 9ms
memory: 7636kb
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: 3ms
memory: 7700kb
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: 9ms
memory: 7720kb
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
Time Limit Exceeded
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...