結果

問題 No.1830 Balanced Majority
ユーザー kabipoyokabipoyo
提出日時 2022-02-04 22:22:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,142 bytes
コンパイル時間 2,427 ms
コンパイル使用メモリ 200,172 KB
実行使用メモリ 24,300 KB
平均クエリ数 7.15
最終ジャッジ日時 2023-09-02 05:03:16
合計ジャッジ時間 4,163 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,424 KB
testcase_01 AC 25 ms
23,820 KB
testcase_02 AC 25 ms
24,012 KB
testcase_03 AC 25 ms
23,772 KB
testcase_04 AC 24 ms
24,228 KB
testcase_05 AC 25 ms
23,364 KB
testcase_06 AC 24 ms
23,616 KB
testcase_07 AC 26 ms
24,300 KB
testcase_08 AC 25 ms
23,352 KB
testcase_09 AC 27 ms
23,340 KB
testcase_10 AC 26 ms
23,424 KB
testcase_11 AC 27 ms
23,640 KB
testcase_12 AC 25 ms
23,952 KB
testcase_13 AC 26 ms
23,832 KB
testcase_14 AC 26 ms
23,508 KB
testcase_15 AC 27 ms
23,508 KB
testcase_16 AC 26 ms
24,252 KB
testcase_17 AC 27 ms
23,952 KB
testcase_18 AC 25 ms
23,376 KB
testcase_19 AC 24 ms
23,364 KB
testcase_20 AC 23 ms
24,000 KB
testcase_21 AC 26 ms
23,376 KB
testcase_22 AC 25 ms
23,640 KB
testcase_23 AC 25 ms
23,352 KB
testcase_24 AC 26 ms
23,820 KB
testcase_25 AC 23 ms
24,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int main() {
	lint N;
	cin >> N;

	lint a=0, b=0, c=0, x, y, z;
	std::cout << "?" << ' ' << 1 << endl;
	cin >> x;
	std::cout << "?" << ' ' << N-1 << endl;
	cin >> y;
	if (x == 0 && y == N/2-1) {
		std::cout << "!" << ' ' << 2 << ' ' << N-1 << endl;
		exit(0);
	} else if (x == 1 && y == N/2) {
		std::cout << "!" << ' ' << 2 << ' ' << N-1 << endl;
		exit(0);
	}

	std::cout << "?" << ' ' << N/2 << endl;
	cin >> z;
	if (z*2 == N/2) {
		std::cout << "!" << ' ' << 1 << ' ' << N/2 << endl;
		exit(0);
	}
	if (z*2 >= N/2) {
		if (x == 0) {
			a = 0, b = N/2;
		} else {
			a = N/2, b = N;
		}
	} else {
		if (x == 0) {
			a = N/2, b = N;
		} else {
			a = 0, b = N/2;
		}
	}
	while (b-a > 1) {
		// list(a) show(b)
		c = (a+b)/2;
		c += c%2;
		std::cout << "?" << ' ' << c << endl;
		cin >> z;
		if (z == c/2) {
			if (c < N/2) std::cout << "!" << ' ' << c+1 << ' ' << N << endl;
			else std::cout << "!" << ' ' << 1 << ' ' << c << endl;
			exit(0);
		} else if (z > c/2) {
			if (c < N/2 && x == 1) a = c;
			else if (c < N/2 && x == 0) b = c;
			else if (c > N/2 && x == 1) a = c;
			else b = c;
		} else {
			if (c < N/2 && x == 1) b = c;
			else if (c < N/2 && x == 0) a = c;
			else if (c > N/2 && x == 1) b = c;
			else a = c;
		}
	}
}
0