結果
| 問題 | No.1830 Balanced Majority | 
| コンテスト | |
| ユーザー |  se1ka2 | 
| 提出日時 | 2022-02-04 22:04:15 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 28 ms / 2,000 ms | 
| コード長 | 616 bytes | 
| コンパイル時間 | 554 ms | 
| コンパイル使用メモリ | 65,680 KB | 
| 実行使用メモリ | 25,964 KB | 
| 平均クエリ数 | 7.54 | 
| 最終ジャッジ日時 | 2024-06-11 11:53:19 | 
| 合計ジャッジ時間 | 2,844 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 25 | 
ソースコード
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int s0, s1;
	cout << "? " << 1 << endl;
	cin >> s0;
	cout << "? " << n - 1 << endl;
	cin >> s1;
	if(s0 != n / 2 - s1){
		cout << "! " << 2 << " " << n - 1 << endl;
		return 0;
	}
	int right = n, left = 0;
	bool f = s0;
	while(right - left > 1){
		int mid = (right + left) / 2;
		cout << "? " << mid << endl;
		int s;
		cin >> s;
		if(s * 2 == mid){
			if(mid * 2 > n) cout << "! " << 1 << " " << mid << endl;
			else cout << "! " << mid + 1 << " " << n << endl;
			return 0;
		}
		if((s * 2 > mid) == f) left = mid;
		else right = mid;
	}
}
            
            
            
        