結果
問題 |
No.253 ロウソクの長さ
|
ユーザー |
![]() |
提出日時 | 2015-07-25 04:26:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 632 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 22,784 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 34.31 |
最終ジャッジ日時 | 2024-07-16 20:51:14 |
合計ジャッジ時間 | 2,755 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d", &ans); | ~~~~~^~~~~~~~~~~~ main.cpp:13:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d", &ans); | ~~~~~^~~~~~~~~~~~ main.cpp:21:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d", &ans); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h> int main(void) { int ans, result; printf("? 100\n"); fflush(stdout); scanf("%d", &ans); if(ans == 0) { result = 100; } else if(ans == -1) { int i = 1; do { printf("? 0\n"); fflush(stdout); scanf("%d", &ans); i++; } while(ans != 0); result = i - 1; } else { int l = 101, r = 1000000000, m = (l + r) / 2, i = 1; while(1) { printf("? %d\n", m - i); fflush(stdout); scanf("%d", &ans); if(ans == 0) { result = m; break; } if(ans == +1) { l = m + 1; } if(ans == -1) { r = m - 1; } m = (l + r) / 2; i++; } } printf("! %d\n", result); fflush(stdout); return 0; }