結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2019-07-05 22:15:48 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 1,030 bytes |
| コンパイル時間 | 378 ms |
| コンパイル使用メモリ | 30,464 KB |
| 実行使用メモリ | 25,476 KB |
| 平均クエリ数 | 200.11 |
| 最終ジャッジ日時 | 2024-07-16 17:21:21 |
| 合計ジャッジ時間 | 2,661 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
#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;
}
akakimidori