結果

問題 No.954 Result
ユーザー RISE70226821RISE70226821
提出日時 2020-10-06 17:22:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 3,239 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 74,076 KB
実行使用メモリ 50,088 KB
最終ジャッジ日時 2023-09-27 08:00:13
合計ジャッジ時間 5,459 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
47,492 KB
testcase_01 AC 39 ms
49,632 KB
testcase_02 AC 41 ms
49,440 KB
testcase_03 AC 39 ms
49,636 KB
testcase_04 AC 39 ms
49,944 KB
testcase_05 AC 40 ms
49,480 KB
testcase_06 AC 41 ms
49,488 KB
testcase_07 AC 41 ms
50,076 KB
testcase_08 AC 39 ms
49,476 KB
testcase_09 AC 37 ms
49,420 KB
testcase_10 AC 38 ms
49,440 KB
testcase_11 AC 38 ms
49,540 KB
testcase_12 AC 41 ms
49,548 KB
testcase_13 AC 38 ms
49,568 KB
testcase_14 AC 40 ms
49,444 KB
testcase_15 AC 40 ms
49,532 KB
testcase_16 AC 40 ms
49,424 KB
testcase_17 AC 39 ms
49,464 KB
testcase_18 AC 40 ms
49,700 KB
testcase_19 AC 39 ms
49,512 KB
testcase_20 AC 40 ms
50,088 KB
testcase_21 AC 41 ms
49,608 KB
testcase_22 AC 41 ms
49,632 KB
testcase_23 AC 40 ms
49,480 KB
testcase_24 AC 40 ms
49,436 KB
testcase_25 AC 41 ms
49,412 KB
testcase_26 AC 40 ms
49,540 KB
testcase_27 AC 41 ms
50,056 KB
testcase_28 AC 41 ms
49,644 KB
testcase_29 AC 40 ms
49,432 KB
testcase_30 AC 40 ms
49,932 KB
testcase_31 AC 40 ms
49,580 KB
testcase_32 AC 41 ms
49,528 KB
testcase_33 AC 39 ms
49,436 KB
testcase_34 AC 40 ms
49,432 KB
testcase_35 AC 40 ms
47,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		// 入力
		FastScanner sc = new FastScanner(System.in);
		long[] A = new long[5];
		for(int i = 0; i < 5; i++){
			A[i] = sc.nextLong();
		}
		
		// フィボナッチ数列作成
		long[] fibo = new long[100];
		Arrays.fill(fibo,-1L);
		fibo[0] = 1L;
		fibo[1] = 1L;
		for(int i = 2; i < 100; i++){
			fibo[i] = fibo[i-1] + fibo[i-2];
			if(fibo[i] > 1000000000000000L){
				break;
			}
		}
		
		// 判定
		int count = 0;
		int startId = -1;
		long num = A[4];
		for(int j = 0; j < 100; j++){
			if(num == fibo[j]){
				startId = j;
				count++;
				break;
			}else if(num < fibo[j]){
				break;
			}
		}
		
		//System.out.println(startId);
		if(startId != -1){
			int id = startId + 1;
			for(int i = 3; i >= 0; i--){
				//System.out.println("A=" + A[i] + " fibo=" + fibo[id]);
				if(A[i] == fibo[id]){
					count++;
					id++;
				}else{
					break;
				}
			}
		}
		
		if(startId == 0){
			startId = 1;
			int id = startId + 1;
			int count2 = 1;
			for(int i = 3; i >= 0; i--){
				if(A[i] == fibo[id]){
					count2++;
					id++;
				}else{
					break;
				}
			}
			//System.out.println(count);
			//System.out.println(count2);
			if(count < count2){
				count = count2;
			}
		}
		
		// 出力
		System.out.println(count);
	}
	
	// 高速スキャナー
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        } 
    }
}

0