結果

問題 No.1830 Balanced Majority
ユーザー umezoumezo
提出日時 2022-02-04 23:19:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,041 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 198,872 KB
実行使用メモリ 24,468 KB
平均クエリ数 8.31
最終ジャッジ日時 2023-09-02 05:54:06
合計ジャッジ時間 4,428 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,568 KB
testcase_01 AC 26 ms
23,412 KB
testcase_02 AC 25 ms
23,568 KB
testcase_03 AC 26 ms
24,072 KB
testcase_04 AC 26 ms
24,336 KB
testcase_05 AC 25 ms
23,460 KB
testcase_06 AC 26 ms
23,856 KB
testcase_07 AC 28 ms
24,060 KB
testcase_08 AC 27 ms
23,892 KB
testcase_09 AC 27 ms
23,856 KB
testcase_10 AC 28 ms
23,472 KB
testcase_11 AC 29 ms
23,436 KB
testcase_12 AC 28 ms
23,856 KB
testcase_13 AC 29 ms
23,688 KB
testcase_14 AC 28 ms
24,108 KB
testcase_15 AC 27 ms
24,324 KB
testcase_16 AC 28 ms
23,700 KB
testcase_17 AC 29 ms
23,436 KB
testcase_18 AC 27 ms
23,700 KB
testcase_19 AC 26 ms
23,436 KB
testcase_20 AC 26 ms
24,324 KB
testcase_21 AC 28 ms
24,096 KB
testcase_22 AC 28 ms
24,072 KB
testcase_23 AC 28 ms
24,276 KB
testcase_24 AC 27 ms
23,424 KB
testcase_25 AC 26 ms
24,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0