結果

問題 No.314 ケンケンパ
ユーザー taku-techtaku-tech
提出日時 2021-05-27 15:50:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 2,953 ms
コンパイル使用メモリ 77,736 KB
実行使用メモリ 45,884 KB
最終ジャッジ日時 2024-04-24 03:01:32
合計ジャッジ時間 6,229 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 106 ms
40,372 KB
testcase_02 AC 114 ms
41,236 KB
testcase_03 AC 117 ms
41,492 KB
testcase_04 AC 113 ms
41,336 KB
testcase_05 AC 105 ms
40,244 KB
testcase_06 AC 107 ms
40,360 KB
testcase_07 AC 102 ms
40,208 KB
testcase_08 AC 115 ms
41,424 KB
testcase_09 AC 117 ms
40,372 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package no_0314;

import java.util.Scanner;
import java.util.stream.LongStream;

public class KenkenPa02 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

//		while(true) {
		int N = sc.nextInt();

		long ways = 0;
		long[][] prev = {{0L, 0L},
					    {1L, 1L}};
		

		if(N == 1) {
			ways = 1;
			System.out.println(ways);
			return;
		}else if(N == 2) {
			ways = 2;
			System.out.println(ways);
			return;
		}

		for(int i = 3; i <= N; i++) {
			long[][] temp = new long[2][2];
			temp[1][1] = prev[0][1];
			temp[1][0] = prev[0][1] + prev[1][1];
			temp[0][1] = prev[1][0];
			prev = temp.clone();
		}

		for(long[] p: prev) {
			ways += LongStream.of(p).sum();
		}
		System.out.println(ways % (1000000000 + 7));
//	}
	}

}
0