結果

問題 No.850 企業コンテスト2位
ユーザー akakimidoriakakimidori
提出日時 2019-07-05 22:15:48
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,030 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 29,488 KB
実行使用メモリ 24,312 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:28:28
合計ジャッジ時間 2,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,204 KB
testcase_01 AC 24 ms
24,216 KB
testcase_02 AC 22 ms
23,604 KB
testcase_03 AC 25 ms
24,240 KB
testcase_04 AC 24 ms
24,312 KB
testcase_05 AC 23 ms
23,352 KB
testcase_06 AC 23 ms
23,988 KB
testcase_07 AC 25 ms
23,556 KB
testcase_08 AC 29 ms
23,544 KB
testcase_09 AC 28 ms
24,240 KB
testcase_10 AC 31 ms
24,240 KB
testcase_11 AC 33 ms
23,460 KB
testcase_12 AC 33 ms
23,544 KB
testcase_13 AC 32 ms
23,748 KB
testcase_14 AC 33 ms
23,280 KB
testcase_15 AC 32 ms
23,280 KB
testcase_16 AC 32 ms
23,616 KB
testcase_17 AC 35 ms
23,340 KB
testcase_18 AC 33 ms
23,304 KB
testcase_19 AC 33 ms
24,228 KB
testcase_20 AC 33 ms
23,940 KB
testcase_21 AC 34 ms
23,436 KB
testcase_22 AC 32 ms
23,964 KB
testcase_23 AC 33 ms
24,012 KB
testcase_24 AC 34 ms
24,252 KB
testcase_25 AC 32 ms
23,928 KB
testcase_26 AC 34 ms
24,168 KB
testcase_27 AC 23 ms
23,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

i32 query (i32 x, i32 y) {
  printf ("? %" PRIi32 " %" PRIi32 "\n", x, y);
  fflush (stdout);
  i32 ans;
  scanf ("%" SCNi32, &ans);
  return ans;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 size = 1;
  while (size < n) size *= 2;
  i32 *s = ALLOC (2 * size, i32);
  for (i32 i = 0; i < n; ++i) {
    s[i + size] = i + 1;
  }
  for (i32 i = size - 1; i >= 1; --i) {
    if (s[2 * i] == 0) continue;
    if (s[2 * i + 1] == 0) {
      s[i] = s[2 * i];
    } else {
      s[i] = query (s[2 * i], s[2 * i + 1]);
    }
  }
  i32 winner = s[1];
  i32 second = s[2] + s[3] - winner;
  for (i32 i = 2; i < size; ++i) {
    if (s[i] != winner) continue;
    if (s[2 * i] != 0 && s[2 * i + 1] != 0) {
      second = query (second, s[2 * i] + s[2 * i + 1] - winner);
    }
  }
  printf ("! %" PRIi32 "\n", second);
}

int main (void) {
  run();
  return 0;
}
0