結果

問題 No.954 Result
ユーザー htensai
提出日時 2019-12-18 13:14:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 77,000 KB
実行使用メモリ 37,020 KB
最終ジャッジ日時 2024-07-04 12:37:43
合計ジャッジ時間 4,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 7
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long[] arr = new long[5];
        for (int i = 4; i >=0; i--) {
            arr[i] = Long.parseLong(br.readLine());
        }
        if (arr[0] == 1) {
            int count = 1;
            if (arr[1] == 1 || arr[1] == 2) {
                count++;
                for (int i = 2; i < 5; i++) {
                    if (arr[i] == arr[i - 1] + arr[i - 2]) {
                        count++;
                    } else {
                        break;
                    }
                }
            }
            System.out.println(count);
            return;
        }
        int idx = 0;
        int count = 0;
        long prepre = 1;
        long pre = 1;
        while (idx < 5 && pre <= arr[idx]) {
            long now = pre + prepre;
            if (arr[idx] == now) {
                idx++;
                count++;
            } else if (count != 0) {
                break;
            }
            prepre = pre;
            pre = now;
        }
        System.out.println(count);
    }
}
0