結果

問題 No.1830 Balanced Majority
コンテスト
ユーザー se1ka2
提出日時 2022-02-04 22:04:15
言語 C++14
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 58 ms / 2,000 ms
+ 0µs
コード長 616 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 296 ms
コンパイル使用メモリ 73,688 KB
実行使用メモリ 6,016 KB
平均クエリ数 7.54
最終ジャッジ日時 2026-07-25 11:30:05
合計ジャッジ時間 1,954 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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