結果

問題 No.1830 Balanced Majority
ユーザー mannshi222jpmannshi222jp
提出日時 2022-02-04 23:30:42
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,110 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 27,788 KB
実行使用メモリ 24,372 KB
平均クエリ数 9.77
最終ジャッジ日時 2023-09-02 06:02:13
合計ジャッジ時間 4,298 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int main()
{
        int N;
        int top;
        int num;
        int sum;
        int prev;
        int tmp;

        scanf("%d", &N );

        prev = 0;
        top = N/2;
        sum = 0;

        while( 1 ) {
                printf("? %d\n", top ); fflush( stdout );
                scanf( "%d", &num );
                if( num == -1 ) {
                        return(0);
                }
                if( sum + num == N / 2 ) {
                        if( top == N ) {
                                printf("! %d %d\n", 2, N-1  );fflush( stdout );
                                return 0;
                        }

                        printf("! %d %d\n", 1, top );fflush( stdout );
                        return 0;
                }
                if( sum + num < N /2 ) {
                        top = ( top + N ) /2 + ( top + N ) % 2;
                }
                else {
                        tmp = top;
                        top = ( top + prev ) / 2 + ( top + prev ) %2;
                        prev = top;
                }
        }
        return 0;
}
0