結果

問題 No.1286 Stone Skipping
ユーザー 37zigen37zigen
提出日時 2020-11-14 00:16:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 4,795 bytes
コンパイル時間 2,846 ms
コンパイル使用メモリ 75,072 KB
実行使用メモリ 49,588 KB
最終ジャッジ日時 2023-09-30 16:09:59
合計ジャッジ時間 5,434 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,120 KB
testcase_01 AC 45 ms
49,224 KB
testcase_02 AC 47 ms
49,020 KB
testcase_03 AC 45 ms
49,216 KB
testcase_04 AC 44 ms
49,092 KB
testcase_05 AC 46 ms
49,240 KB
testcase_06 AC 44 ms
49,108 KB
testcase_07 AC 45 ms
49,128 KB
testcase_08 AC 47 ms
49,388 KB
testcase_09 AC 46 ms
49,208 KB
testcase_10 AC 46 ms
49,588 KB
testcase_11 AC 46 ms
49,004 KB
testcase_12 AC 46 ms
48,920 KB
testcase_13 AC 47 ms
48,976 KB
testcase_14 AC 48 ms
49,120 KB
testcase_15 AC 48 ms
48,920 KB
testcase_16 AC 49 ms
49,248 KB
testcase_17 AC 48 ms
49,156 KB
testcase_18 AC 44 ms
49,152 KB
testcase_19 AC 45 ms
49,144 KB
testcase_20 AC 48 ms
49,040 KB
testcase_21 AC 47 ms
49,076 KB
testcase_22 AC 47 ms
49,212 KB
testcase_23 AC 46 ms
47,316 KB
testcase_24 AC 47 ms
49,164 KB
testcase_25 AC 47 ms
49,104 KB
testcase_26 AC 47 ms
49,184 KB
testcase_27 AC 48 ms
47,136 KB
testcase_28 AC 47 ms
48,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
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();
        }
    }
    
    int nextInt() {
    	return (int)nextLong();
    }
}



class PersistentStack {
	PersistentStack next=null;
	int val;

	public PersistentStack(int val, PersistentStack next) {
		this.val=val;
		this.next=next;
	}
	
	public PersistentStack() {
	}
	
	int peek() {
		return val;
	}
	
	PersistentStack pop() {
		if (next!=null) next=next.eval();
		return next;
	}
	
	static PersistentStack push(PersistentStack x, int v) {
		return new PersistentStack(v, x);
	}
	
	static PersistentStack concat(PersistentStack x, PersistentStack y) {
		if (x==null) return y.eval();
		else return new PersistentStack(x.val, new PersistentStack() {
				@Override
				PersistentStack eval() {
					return PersistentStack.concat(x.pop(), y);
				}
			});
	}
	
	static PersistentStack reverse(PersistentStack head) {
		return new PersistentStack () {
			@Override
			PersistentStack eval() {
				PersistentStack ret=null;
				for (PersistentStack x=head;x!=null;x=x.pop()) {
					ret=PersistentStack.push(ret, x.peek());
				}
				return ret;
			}
		};
	}
	
	PersistentStack eval() {
		return this;
	}
}

class PersistentQueue {
	int front_size=0;
	int back_size=0;
	PersistentStack front=null;
	PersistentStack back=null;
	
	public PersistentQueue(PersistentStack front, int front_size, PersistentStack back, int back_size) {
		this.front_size=front_size;
		this.back_size=back_size;
		this.front=front;
		this.back=back;
	}
	
	public PersistentQueue() {
	}
	
	boolean isEmpty() {
		return front_size==0;
	}
	
	int peek() {
		return front.peek();
	}
	
	PersistentQueue push(int x) {
		return new PersistentQueue(front, front_size, PersistentStack.push(back, x), back_size+1).normalize();
	}
	
	PersistentQueue pop() {
		return new PersistentQueue(front.pop(), front_size-1, back, back_size).normalize();
	}
	
	PersistentQueue normalize() {
		if (front_size >= back_size) return this;
		else {
			return new PersistentQueue(PersistentStack.concat(front, PersistentStack.reverse(back)), front_size+back_size, null, 0);
		}
	}

}

public class Main {
	
	long pow(long a,long n,long p) {
		return n!=0?pow(a*a%p,n/2,p)*(n%2==1?a:1)%p:1;
	}
	
	long f(int t,long x) {
		long sum=0;
		for (int j=0;j<t;++j) {
			sum+=x;
			x/=2;
		}
		return sum;
		
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		long D=sc.nextLong();
		long ans=D;
		
		for (int t=2;t<=60;++t) {
			long ok=D;//>=
			long ng=0;//<
			while (ok-ng!=1) {
				long middle=(ok+ng)/2;
				if (f(t,middle)>=D)  ok=middle;
				else ng=middle;
			}
			if (f(t,ok)==D) {
				ans=Math.min(ans, ok);
			}
		}
		System.out.println(ans);
	}
	
	static void  tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
    public static void main(String[] args) {
    	new Main().run();
    }
}
0