結果

問題 No.1152 10億ゲーム
ユーザー uwiuwi
提出日時 2020-08-15 17:19:45
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,744 bytes
コンパイル時間 2,983 ms
コンパイル使用メモリ 75,996 KB
実行使用メモリ 74,324 KB
平均クエリ数 24.68
最終ジャッジ日時 2023-09-24 05:38:41
合計ジャッジ時間 13,890 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
71,484 KB
testcase_01 AC 166 ms
72,392 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 167 ms
71,040 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 165 ms
70,776 KB
testcase_09 AC 149 ms
69,720 KB
testcase_10 AC 144 ms
69,228 KB
testcase_11 AC 164 ms
69,156 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 159 ms
70,440 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 168 ms
71,148 KB
testcase_21 AC 158 ms
70,752 KB
testcase_22 AC 168 ms
70,912 KB
testcase_23 AC 168 ms
70,456 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 166 ms
71,964 KB
testcase_39 AC 161 ms
70,820 KB
testcase_40 AC 163 ms
69,592 KB
testcase_41 AC 164 ms
71,896 KB
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 163 ms
70,944 KB
testcase_47 AC 166 ms
71,656 KB
testcase_48 AC 159 ms
72,144 KB
testcase_49 AC 162 ms
72,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no1xxx;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class No1152 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static int[] dec(int x)
	{
		int mx = 0, my = 0;
		while(x % 2 == 0){
			x /= 2;
			mx++;
		}
		while(x % 5 == 0){
			x /= 5;
			my++;
		}
		return new int[]{mx, my};
	}
	
	static int enc(int[] a)
	{
		int ret = 1;
		for(int i = 0;i < a[0];i++)ret *= 2;
		for(int i = 0;i < a[1];i++)ret *= 5;
		return ret;
	}
	
	static void solve()
	{
		int x1 = ni();
		while(true){
			int x2 = ni();
			if(x1 == x2)break;
			int[] my = dec(x1);
			int[] en = dec(x2);
			if(Math.abs(my[0] - en[0]) > Math.abs(my[1] - en[1])){
				if(my[0] < en[0]){
					my[0]++;
				}else{
					my[0]--;
				}
			}else if(Math.abs(my[0] - en[0]) < Math.abs(my[1] - en[1])){
				if(my[1] < en[1]){
					my[1]++;
				}else{
					my[1]--;
				}
			}else{
				Random gen = new Random();
				if(gen.nextBoolean()){
					if(my[0] < en[0]){
						my[0]++;
					}else{
						my[0]--;
					}
				}else{
					if(my[1] < en[1]){
						my[1]++;
					}else{
						my[1]--;
					}
				}
			}
			int to = enc(my);
			out.println(to);
			out.flush();
			if(to == x2)break;
			x1 = to;
		}
	}
	
	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)); }
}
0