結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
55,788 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 109 ms
55,936 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 118 ms
55,884 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 110 ms
55,952 KB
testcase_16 AC 114 ms
55,872 KB
testcase_17 AC 114 ms
55,676 KB
testcase_18 AC 110 ms
56,284 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 112 ms
55,684 KB
testcase_23 WA -
testcase_24 AC 107 ms
56,176 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 110 ms
55,644 KB
testcase_29 AC 106 ms
55,716 KB
testcase_30 AC 109 ms
56,036 KB
testcase_31 WA -
testcase_32 AC 105 ms
55,956 KB
testcase_33 WA -
testcase_34 AC 119 ms
56,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.net.NetworkInterface;
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;
		long[] aaa = new long[n-2];
		aaa[0]=1;
		aaa[0]=1;
		for(int i=2;i<n-2;i++) aaa[i]=aaa[i-1]+aaa[i-2];
		while(sa>0){
			int x = upper_bound(aaa, sa)-1;
			if(x<0) x=n-3;
			sa-=fib[x];
			ans++;
		}
		System.out.println(ans);
	}
}
0