結果

問題 No.1152 10億ゲーム
ユーザー 37zigen37zigen
提出日時 2020-07-09 05:10:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,381 bytes
コンパイル時間 3,430 ms
コンパイル使用メモリ 78,996 KB
実行使用メモリ 81,304 KB
平均クエリ数 27.48
最終ジャッジ日時 2023-09-24 03:51:03
合計ジャッジ時間 35,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 577 ms
78,500 KB
testcase_01 AC 549 ms
79,636 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 569 ms
80,708 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 548 ms
79,340 KB
testcase_09 AC 552 ms
79,604 KB
testcase_10 AC 565 ms
78,616 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 569 ms
78,988 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 567 ms
77,508 KB
testcase_21 AC 563 ms
78,920 KB
testcase_22 AC 584 ms
78,200 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 565 ms
79,972 KB
testcase_49 AC 567 ms
79,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
    	return (int)nextLong();
    }
}

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	HashMap<List<Integer>,Integer> dp=new HashMap<>();
	final int INF=Integer.MAX_VALUE/3;
	final long M=(long)1e9;
	ArrayList<Integer> divs=new ArrayList<>();
	{
		for (int i=0;i<=9;++i) {
			for (int j=0;j<=9;++j) {
				int d=(int)Math.round(Math.pow(2, i)*Math.pow(5, j));
				divs.add(d);
			}
		}
		Collections.sort(divs);
		for (int d:divs) dp.put(List.of(d,d), 0);
	}
	
	int g(int x,int i) {
		if (i==0&&x%2==0) return x/2;
		else if (i==1&&x%5==0) return x/5;
		else if (i==2) return (int)Math.min((long)2*x, M);
		else if (i==3) return (int)Math.min((long)5*x, M);
		else return 0;
	}	
	
	void build() {
		for (int t=0;t<100;++t) {
			for (int x0:divs) {
				in:for (int x1:divs) {


					if (dp.containsKey(List.of(x0,x1))) continue;
					

					for (int i=0;i<4;++i) {
						long nx0=g(x0,i);
						if (nx0==x0 || nx0==0 || M%nx0!=0) continue;
						if (nx0==x1) {
							dp.put(List.of(x0,x1), 1);
							continue in;
						}
					}
					int ret=INF;
					in2:for (int i=0;i<4;++i) {
						int nx0=g(x0,i);
						if (nx0==x0 || nx0==0 || M%nx0!=0) continue;
						int tmp=0;
						for (int j=0;j<4;++j) {
							int nx1=g(x1,j);
							if (nx1==x1 || nx1==0 || M%nx1!=0) continue;

							if (!dp.containsKey(List.of(nx0,nx1))) {
								continue in2;
							}
							tmp=Math.max(tmp, 1+dp.get(List.of(nx0,nx1)));
						}
						ret=Math.min(ret, tmp);
					}
					if (ret!=INF) dp.put(List.of(x0,x1), ret);
				}
			}
		}
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		build();
		int x0=sc.nextInt();
		for (int t=0;t<35;++t) {
			int x1=sc.nextInt();
			for (int i=0;i<4;++i) {
				if (x0==x1) return;
				int nx0=g(x0,i);
				if (nx0==x0 || nx0==0 || M%nx0!=0) continue;
				if (x1==nx0) {
					System.out.println(nx0);
					return;
				}
				int next=0;
				for (int j=0;j<4;++j) {
					int nx1=g(x1,j);
					if (nx1==x1 || nx1==0 || M%nx1!=0) continue;
					next=Math.max(next,dp.get(List.of(nx0,nx1)));
				}
				x0=nx0;
				System.out.println(x0);
				if (x0==x1) return;
				break;
			}
		}
	}
	
	
	
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

0