結果

問題 No.314 ケンケンパ
ユーザー jp_stejp_ste
提出日時 2016-02-18 13:03:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 1,000 ms
コード長 430 bytes
コンパイル時間 2,279 ms
コンパイル使用メモリ 74,740 KB
実行使用メモリ 63,616 KB
最終ジャッジ日時 2023-10-23 18:05:17
合計ジャッジ時間 5,773 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
63,616 KB
testcase_01 AC 135 ms
57,372 KB
testcase_02 AC 131 ms
57,152 KB
testcase_03 AC 131 ms
57,296 KB
testcase_04 AC 130 ms
57,424 KB
testcase_05 AC 133 ms
57,472 KB
testcase_06 AC 132 ms
57,296 KB
testcase_07 AC 136 ms
57,100 KB
testcase_08 AC 132 ms
57,508 KB
testcase_09 AC 134 ms
57,356 KB
testcase_10 AC 133 ms
57,344 KB
testcase_11 AC 140 ms
57,124 KB
testcase_12 AC 139 ms
57,148 KB
testcase_13 AC 138 ms
57,400 KB
testcase_14 AC 135 ms
57,620 KB
testcase_15 AC 140 ms
57,384 KB
testcase_16 AC 141 ms
57,472 KB
testcase_17 AC 142 ms
57,328 KB
testcase_18 AC 151 ms
59,856 KB
testcase_19 AC 150 ms
63,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scan = new Scanner(System.in)) {
			int N = scan.nextInt();
			if(N <= 2) {
				System.out.println(N);
			} else {
				long dp[] = new long[N+1];
				dp[0] = 1;
				dp[1] = 2;
				dp[2] = 2;
				for(int i=3; i<=N; i++) {
					dp[i] = ( dp[i-2] + dp[i-3] ) % (1000000000+7);
				}
				System.out.println(dp[N-1]);
			}
		}
	}
}
0