結果

問題 No.1830 Balanced Majority
ユーザー kabipoyokabipoyo
提出日時 2022-02-04 22:01:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,812 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 200,600 KB
実行使用メモリ 36,300 KB
平均クエリ数 2.35
最終ジャッジ日時 2023-09-02 04:51:26
合計ジャッジ時間 7,532 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,868 KB
testcase_01 AC 24 ms
24,336 KB
testcase_02 AC 24 ms
24,012 KB
testcase_03 AC 23 ms
23,676 KB
testcase_04 AC 23 ms
23,628 KB
testcase_05 AC 24 ms
24,336 KB
testcase_06 AC 24 ms
23,664 KB
testcase_07 AC 25 ms
23,448 KB
testcase_08 AC 26 ms
23,364 KB
testcase_09 AC 25 ms
24,312 KB
testcase_10 AC 25 ms
23,652 KB
testcase_11 WA -
testcase_12 AC 25 ms
24,072 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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 == N/4 && (N/2) % 2 == 0) {
		std::cout << "!" << ' ' << 1 << ' ' << N/2 << endl;
		exit(0);
	}
	if (z >= N/4) {
		a = N/2, b = N;
	} else {
		a = 0, b = N/2;
	}
	while (b-a > 1) {
		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) b = c;
			else a = c;
		}
	}
}
0