結果

問題 No.320 眠れない夜に
ユーザー htensaihtensai
提出日時 2019-11-22 08:38:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 2,589 ms
コンパイル使用メモリ 72,424 KB
実行使用メモリ 56,052 KB
最終ジャッジ日時 2023-08-01 10:34:35
合計ジャッジ時間 8,716 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,912 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 124 ms
55,868 KB
testcase_04 AC 122 ms
55,792 KB
testcase_05 AC 121 ms
55,820 KB
testcase_06 AC 123 ms
56,052 KB
testcase_07 AC 122 ms
56,048 KB
testcase_08 AC 122 ms
55,500 KB
testcase_09 AC 122 ms
55,988 KB
testcase_10 AC 122 ms
55,480 KB
testcase_11 AC 122 ms
55,572 KB
testcase_12 AC 124 ms
55,648 KB
testcase_13 AC 124 ms
55,832 KB
testcase_14 AC 123 ms
55,548 KB
testcase_15 AC 125 ms
55,492 KB
testcase_16 AC 123 ms
55,432 KB
testcase_17 AC 123 ms
56,048 KB
testcase_18 AC 123 ms
55,696 KB
testcase_19 AC 122 ms
55,692 KB
testcase_20 AC 123 ms
55,956 KB
testcase_21 AC 123 ms
55,488 KB
testcase_22 AC 122 ms
55,556 KB
testcase_23 WA -
testcase_24 AC 122 ms
55,648 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 120 ms
55,488 KB
testcase_29 AC 121 ms
55,624 KB
testcase_30 AC 124 ms
55,504 KB
testcase_31 AC 122 ms
55,648 KB
testcase_32 AC 119 ms
55,600 KB
testcase_33 AC 122 ms
55,544 KB
testcase_34 AC 120 ms
55,832 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