結果

問題 No.320 眠れない夜に
ユーザー threepipes_sthreepipes_s
提出日時 2015-12-03 06:19:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 72,372 KB
実行使用メモリ 56,360 KB
最終ジャッジ日時 2023-10-12 09:24:58
合計ジャッジ時間 8,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,332 KB
testcase_01 AC 124 ms
56,192 KB
testcase_02 AC 124 ms
53,932 KB
testcase_03 AC 123 ms
56,164 KB
testcase_04 AC 124 ms
55,832 KB
testcase_05 AC 124 ms
55,924 KB
testcase_06 AC 123 ms
56,268 KB
testcase_07 AC 123 ms
56,312 KB
testcase_08 AC 124 ms
56,180 KB
testcase_09 AC 125 ms
56,256 KB
testcase_10 AC 123 ms
56,204 KB
testcase_11 AC 122 ms
55,936 KB
testcase_12 AC 124 ms
56,216 KB
testcase_13 AC 121 ms
56,264 KB
testcase_14 AC 123 ms
55,816 KB
testcase_15 AC 124 ms
56,356 KB
testcase_16 AC 124 ms
56,228 KB
testcase_17 AC 121 ms
55,816 KB
testcase_18 AC 125 ms
55,860 KB
testcase_19 AC 123 ms
55,948 KB
testcase_20 AC 125 ms
55,564 KB
testcase_21 AC 126 ms
55,864 KB
testcase_22 AC 126 ms
56,044 KB
testcase_23 AC 124 ms
55,516 KB
testcase_24 AC 122 ms
53,876 KB
testcase_25 AC 122 ms
56,080 KB
testcase_26 AC 124 ms
56,196 KB
testcase_27 AC 123 ms
55,812 KB
testcase_28 AC 122 ms
55,724 KB
testcase_29 AC 121 ms
56,360 KB
testcase_30 AC 122 ms
55,700 KB
testcase_31 AC 123 ms
55,836 KB
testcase_32 AC 126 ms
55,808 KB
testcase_33 AC 123 ms
55,784 KB
testcase_34 AC 120 ms
56,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args)
	{(new Solve()).solve();}
}

class Solve{
	void solve(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long m = in.nextLong();
		System.out.println(getMistake(n, m));
		in.close();
	}
	
	int getMistake(int n, long m){
		long[] fib = new long[n];
		fib[0] = fib[1] = 1;
		for(int i=2; i<n; i++){
			fib[i] = fib[i-1]+fib[i-2];
		}
		int count = 0;
		long diff = fib[n-1]-m;
		for(int i=n-3; i>=0; i--){
			if(diff>=fib[i]){
				diff -= fib[i];
				count++;
			}
			if(diff==0) return count;
		}
		return -1;
	}
}
0