結果

問題 No.320 眠れない夜に
ユーザー kou6839kou6839
提出日時 2015-12-13 14:22:43
言語 Java19
(openjdk 21)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,259 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 75,388 KB
実行使用メモリ 57,556 KB
最終ジャッジ日時 2023-10-13 14:53:22
合計ジャッジ時間 8,009 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,492 KB
testcase_01 AC 131 ms
55,812 KB
testcase_02 AC 127 ms
56,068 KB
testcase_03 AC 125 ms
55,824 KB
testcase_04 AC 126 ms
56,192 KB
testcase_05 AC 126 ms
56,008 KB
testcase_06 AC 125 ms
55,584 KB
testcase_07 AC 124 ms
55,572 KB
testcase_08 AC 126 ms
55,988 KB
testcase_09 AC 127 ms
55,496 KB
testcase_10 AC 125 ms
55,652 KB
testcase_11 AC 127 ms
55,860 KB
testcase_12 AC 126 ms
55,840 KB
testcase_13 AC 125 ms
56,112 KB
testcase_14 AC 125 ms
56,104 KB
testcase_15 AC 124 ms
55,724 KB
testcase_16 AC 125 ms
55,772 KB
testcase_17 AC 125 ms
55,500 KB
testcase_18 AC 126 ms
55,800 KB
testcase_19 AC 126 ms
56,256 KB
testcase_20 AC 131 ms
56,020 KB
testcase_21 AC 126 ms
56,076 KB
testcase_22 AC 124 ms
55,856 KB
testcase_23 AC 124 ms
54,176 KB
testcase_24 AC 125 ms
56,100 KB
testcase_25 AC 126 ms
55,856 KB
testcase_26 AC 125 ms
55,960 KB
testcase_27 AC 127 ms
56,072 KB
testcase_28 AC 124 ms
55,564 KB
testcase_29 AC 123 ms
55,772 KB
testcase_30 AC 123 ms
57,556 KB
testcase_31 AC 124 ms
56,108 KB
testcase_32 AC 126 ms
56,156 KB
testcase_33 AC 126 ms
56,020 KB
testcase_34 AC 126 ms
55,936 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();
		if(m<1){ System.out.println(-1);
		return;}
		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[1]=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-=aaa[x];
			aaa[x]=1;
			Arrays.sort(aaa);
			ans++;
		}
		System.out.println(ans);
	}
}
0