結果
問題 | No.1830 Balanced Majority |
ユーザー |
![]() |
提出日時 | 2022-02-04 23:19:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 1,041 bytes |
コンパイル時間 | 2,196 ms |
コンパイル使用メモリ | 193,092 KB |
最終ジャッジ日時 | 2025-01-27 19:52:52 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 25 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; ll f(ll a,ll b){ return 2*b-a; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; int cl,cr; cout<<"? "<<1<<endl; cin>>cl; cl=f(1,cl); cout<<"? "<<n-1<<endl; cin>>cr; cr=f(n-1,cr); if(cl==cr) cout<<"! "<<2<<" "<<n-1<<endl; else if(cl>cr){ int ok=n-1,ng=1; while(ok-ng>1){ int mid=(ok+ng)/2; cout<<"? "<<mid<<endl; int t; cin>>t; if(f(mid,t)<0) ok=mid; else ng=mid; } int s=ok-1; if(s>=n/2) cout<<"! "<<1<<" "<<s<<endl; else cout<<"! "<<s+1<<" "<<n<<endl; } else{ int ok=n-1,ng=1; while(ok-ng>1){ int mid=(ok+ng)/2; cout<<"? "<<mid<<endl; int t; cin>>t; if(f(mid,t)>0) ok=mid; else ng=mid; } int s=ok-1; if(s>=n/2) cout<<"! "<<1<<" "<<s<<endl; else cout<<"! "<<s+1<<" "<<n<<endl; } return 0; }