結果

問題 No.320 眠れない夜に
ユーザー htensaihtensai
提出日時 2019-11-22 08:38:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 75,824 KB
実行使用メモリ 56,272 KB
最終ジャッジ日時 2024-04-19 10:08:36
合計ジャッジ時間 6,959 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
54,240 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 116 ms
41,912 KB
testcase_04 AC 105 ms
41,452 KB
testcase_05 AC 108 ms
41,696 KB
testcase_06 AC 102 ms
41,456 KB
testcase_07 AC 103 ms
41,668 KB
testcase_08 AC 117 ms
41,624 KB
testcase_09 AC 111 ms
41,288 KB
testcase_10 AC 114 ms
41,816 KB
testcase_11 AC 115 ms
41,732 KB
testcase_12 AC 106 ms
41,532 KB
testcase_13 AC 120 ms
41,592 KB
testcase_14 AC 122 ms
41,732 KB
testcase_15 AC 116 ms
41,412 KB
testcase_16 AC 106 ms
41,860 KB
testcase_17 AC 103 ms
41,416 KB
testcase_18 AC 107 ms
41,832 KB
testcase_19 AC 101 ms
41,396 KB
testcase_20 AC 116 ms
41,556 KB
testcase_21 AC 116 ms
40,084 KB
testcase_22 AC 118 ms
41,276 KB
testcase_23 WA -
testcase_24 AC 111 ms
41,520 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 111 ms
41,468 KB
testcase_29 AC 114 ms
41,152 KB
testcase_30 AC 115 ms
41,692 KB
testcase_31 AC 111 ms
41,444 KB
testcase_32 AC 113 ms
41,316 KB
testcase_33 AC 121 ms
41,452 KB
testcase_34 AC 107 ms
41,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();
		long prepre = 1;
		long prev = 1;
	    TreeSet<Long> set = new TreeSet<>();
	    set.add(1L);
		for (int i = 3; i <= n; i++) {
		    long cur = prepre + prev;
		    prepre = prev;
		    prev = cur;
		    set.add(prev);
		}
		long value = prev - m;
		if (value < 0) {
		    System.out.println(-1);
		    return;
		}
		int count = 0;
		while (value > 0) {
		    value -= set.floor(value);
		    count++;
		}
		System.out.println(count);
	}
}
0