結果
| 問題 |
No.253 ロウソクの長さ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-24 22:57:32 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 184 ms / 2,000 ms |
| コード長 | 1,375 bytes |
| コンパイル時間 | 4,130 ms |
| コンパイル使用メモリ | 88,492 KB |
| 実行使用メモリ | 71,260 KB |
| 平均クエリ数 | 35.53 |
| 最終ジャッジ日時 | 2024-07-16 20:49:01 |
| 合計ジャッジ時間 | 11,173 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
ソースコード
package contest;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Q687 {
static Scanner in;
static PrintWriter out;
static String INPUT = "";
static void solve()
{
long low = 10, high = 1000000001;
int turn = 0;
for(long i = low;;i*=2){
out.println("? " + i);
out.flush();
int res = ni();
if(res == 0){
low = i+turn; high = i+turn;
out.println("! " + low);
out.flush();
return;
}else if(res == 1){
low = i+1+turn;
}else{
high = i+turn;
break;
}
turn++;
}
turn++;
while(true){
long h = (high-turn)+(low-turn)>>>1;
out.println("? " + h);
out.flush();
int res = ni();
if(res == 0){
low = h+turn; high = h+turn;
out.println("! " + low);
out.flush();
return;
}else if(res == 1){
low = h+1+turn;
}else{
high = h+turn;
}
turn++;
}
}
public static void main(String[] args) throws Exception
{
in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
out = new PrintWriter(System.out);
solve();
out.flush();
}
static int ni() { return Integer.parseInt(in.next()); }
static long nl() { return Long.parseLong(in.next()); }
static double nd() { return Double.parseDouble(in.next()); }
static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}