結果

問題 No.253 ロウソクの長さ
ユーザー 37zigen
提出日時 2016-03-22 17:15:31
言語 Java
(openjdk 23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 921 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 79,816 KB
実行使用メモリ 31,908 KB
最終ジャッジ日時 2024-07-16 23:07:18
合計ジャッジ時間 8,465 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder253;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		System.out.println("?100");
		int a=sc.nextInt();
		int count=0;
		if(a==-1){
			for(int i=0;i<100;i++){
				System.out.println("?0");
				count++;
				int b=sc.nextInt();
				if(b==0){
					System.out.println("!"+count);
					sc.close();
					System.exit(0);
				}
			}
		}else if(a==1){
			int upper=(int)Math.pow(10,9);
			int low=100;
			int mid=(int)(upper+low)/2;

			while(low!=upper){
				count++;
				upper--;
				low--;
				System.out.println("?"+mid);
				int r=sc.nextInt();
				if(r==1){
					mid=(upper+mid)/2;
				}else if(r==-1){
					mid=(low+mid)/2;
				}else if(r==1){
					System.out.println("!"+(mid+count));
					sc.close();
					System.exit(0);
				}
			}
		}else if(a==0){
			System.out.println("!100");
			sc.close();
			System.exit(0);
		}

	}
}

0