結果

問題 No.320 眠れない夜に
ユーザー kou6839kou6839
提出日時 2015-12-13 14:02:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,022 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 73,660 KB
実行使用メモリ 58,032 KB
最終ジャッジ日時 2023-10-13 14:52:19
合計ジャッジ時間 8,109 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,680 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 124 ms
55,668 KB
testcase_04 AC 126 ms
56,132 KB
testcase_05 AC 124 ms
56,004 KB
testcase_06 AC 125 ms
55,992 KB
testcase_07 AC 123 ms
55,948 KB
testcase_08 AC 124 ms
56,036 KB
testcase_09 AC 126 ms
55,604 KB
testcase_10 AC 125 ms
55,752 KB
testcase_11 AC 124 ms
56,032 KB
testcase_12 AC 125 ms
55,792 KB
testcase_13 AC 126 ms
56,064 KB
testcase_14 AC 124 ms
56,164 KB
testcase_15 AC 122 ms
55,984 KB
testcase_16 AC 123 ms
55,976 KB
testcase_17 AC 124 ms
56,120 KB
testcase_18 AC 125 ms
56,280 KB
testcase_19 AC 125 ms
56,056 KB
testcase_20 AC 128 ms
55,956 KB
testcase_21 AC 126 ms
55,900 KB
testcase_22 AC 124 ms
55,436 KB
testcase_23 WA -
testcase_24 AC 123 ms
55,512 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 126 ms
56,064 KB
testcase_29 AC 123 ms
55,684 KB
testcase_30 AC 123 ms
55,772 KB
testcase_31 AC 121 ms
55,420 KB
testcase_32 AC 123 ms
55,672 KB
testcase_33 AC 125 ms
55,628 KB
testcase_34 AC 126 ms
55,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {public static int upper_bound(long[] arr, long key) {
	int len = arr.length;
	int lo = 0;
	int hi = len-1;
	int mid = (lo + hi)/2;
	while (true) {
		long cmp = arr[mid]-key;
		if (cmp == 0 || cmp < 0) {
			lo = mid+1;
			if (hi < lo)
				return mid<len-1?mid+1:-1;
		} else {
			hi = mid-1;
			if (hi < lo)
				return mid;
		}
		mid = (lo + hi)/2;
	}
}
	static long gcd(long a,long b){
		return b == 0 ? a : gcd(b, a%b);
	}
	static long lcm(long a, long b){
		return a*b/gcd(a, b);
	}
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();
		long[] fib = new long[100];
		fib[0]=1;fib[1]=1;
		for(int i=2;i<100;i++) fib[i]=fib[i-1]+fib[i-2];
		long sa = fib[n-1]-m;
		if(sa==0){
			System.out.println(0);
			return;
		}else if(sa<0){
			System.out.println(-1);
			return;
		}
		int ans = 0;
		while(sa>0){
			int x = upper_bound(fib, sa)-1;
			sa-=fib[x];
			ans++;
		}
		System.out.println(ans);
	}
}
0