QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314778 | #7689. Flipping Cards | Albert711 | WA | 0ms | 3776kb | C++20 | 1.3kb | 2024-01-26 10:57:45 | 2024-01-26 10:57:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 1000 + 5;
const int mod = 1000000000;
#define int long long
void solve(){
int n;
cin>>n;
vector<pair<int,int> >a(n+1);
for(int i=1;i<=n;i++) cin>>a[i].first>>a[i].second;
int l=1,r=1e9;
while(l+1<r){
int mid=(r-l)/2+l;
int cnt=0,tmp=0,maxn=0;
for(int i=1;i<=n;i++){
if(a[i].first>=mid) tmp++;
}
for(int i=1;i<=n;i++){
if(a[i].first<mid&&a[i].second>=mid){
cnt++;
maxn=max(maxn,cnt);
}else if(a[i].first>=mid&&a[i].second<mid){
cnt--;
if(cnt<0) cnt=0;
}
}
if(tmp+maxn>=n/2+1){
l=mid;
}else{
r=mid;
}
}
cout<<l<<'\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) solve();
return 0;
}
//void solve() {
// int n;
// cin>>n;
// vector<int> a(n+1);
// vector<int> b(n+1);
// for(int i=1;i<=n;i++) cin>>a[i];
// for(int i=1;i<=n;i++){
// b[i]=a[i]-a[i-1];
// }
//
//}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 3456kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3776kb
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: -100
Wrong Answer
time: 0ms
memory: 3776kb
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:
999999999
result:
wrong answer 1st numbers differ - expected: '1000000000', found: '999999999'