結果

問題 No.954 Result
ユーザー tenten
提出日時 2020-08-25 17:46:36
言語 Java
(openjdk 23)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 3,574 ms
コンパイル使用メモリ 85,604 KB
実行使用メモリ 54,204 KB
最終ジャッジ日時 2024-07-04 13:04:18
合計ジャッジ時間 9,260 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 7
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long[] arr = new long[5];
        for (int i = 4; i >= 0; i--) {
            arr[i] = sc.nextLong();
        }
        long prepre = 1;
        long pre = 1;
        TreeSet<Long> fibo = new TreeSet<>();
        fibo.add(pre);
        while (pre <= 1000000000000000L) {
            long x = pre + prepre;
            fibo.add(x);
            prepre = pre;
            pre = x;
        }
        int ans = 0;
        if (fibo.contains(arr[0])) {
            ans++;
        } else {
            System.out.println(0);
            return;
        }
        int start = 1;
        if (arr[0] == 1 && arr[1] == 1) {
            start++;
            ans++;
        }
        for (int i = start; i < 5; i++) {
            if (fibo.higher(arr[i - 1]) != arr[i]) {
                break;
            }
            ans++;
        }
        System.out.println(ans);
    }
}
0