QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#771361 | #7689. Flipping Cards | xsdgp | WA | 2ms | 11860kb | C++20 | 943b | 2024-11-22 12:08:51 | 2024-11-22 12:08:59 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,a[300005],b[300005];
int c[300005],f[300005],suf[300005];
bool check(int x)
{
for(int i=n;i>=1;i--)
if(a[i]>=x)suf[i]=suf[i+1]+1;
else suf[i]=suf[i+1];
for(int i=1;i<=n;i++)
if(a[i]>=x&&b[i]>=x)c[i]=0;
else if(a[i]>=x)c[i]=-1;
else if(b[i]>=x)c[i]=1;
else c[i]=0;
for(int i=1;i<=n;i++)
f[i]=0;
if(f[0]+suf[1]>=(n+1)/2)return 1;
for(int i=1;i<=n;i++)
{
f[i]=max(c[i],c[i]+f[i-1]);
if(f[i]+suf[i+1]>=(n+1)/2)return 1;
}
return 0;
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i];
int l=1,r=1e9;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))l=mid+1;
else r=mid-1;
}
cout<<l-1<<endl;
}
signed main()
{
ios::sync_with_stdio(false),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
1
2 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11856kb
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: 11860kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11796kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 11768kb
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:
459542270
result:
wrong answer 1st numbers differ - expected: '528957505', found: '459542270'