結果

問題 No.1830 Balanced Majority
ユーザー 👑 ygussanyygussany
提出日時 2022-01-09 10:49:12
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 679 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 39,200 KB
最終ジャッジ日時 2024-04-26 19:44:44
合計ジャッジ時間 6,643 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	
	int x, y;
	printf("? 1\n");
	fflush(stdout);
	scanf("%d\n", &x);
	printf("? %d\n", N - 1);
	fflush(stdout);
	scanf("%d\n", &y);
	if ((x == 1 && y == N / 2) || (x == 0 && y == N / 2 - 1)) {
		printf("! 2 %d\n", N - 1);
		fflush(stdout);
		return 0;
	}
	
	int l = 1, r = N - 1, m, z;
	while (l < r) {
		m = (l + r) / 2;
		printf("? %d\n", m);
		fflush(stdout);
		scanf("%d", &z);
		if (z * 2 == m) {
			l = m;
			break;
		} else if ((x == 1 && z * 2 > m) || (x == 0 && z * 2 < m)) l = m + 1;
		else r = m - 1;
	}
	if (l >= N / 2) printf("! 1 %d\n", l);
	else printf("! %d %d\n", l + 1, N);
	fflush(stdout);
	return 0;
}
0