結果

問題 No.314 ケンケンパ
ユーザー 37zigen37zigen
提出日時 2016-03-25 20:15:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 149 ms / 1,000 ms
コード長 590 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 60,408 KB
最終ジャッジ日時 2024-04-09 23:53:52
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
60,408 KB
testcase_01 AC 127 ms
54,276 KB
testcase_02 AC 127 ms
54,176 KB
testcase_03 AC 129 ms
54,224 KB
testcase_04 AC 134 ms
54,428 KB
testcase_05 AC 129 ms
54,356 KB
testcase_06 AC 127 ms
54,364 KB
testcase_07 AC 130 ms
54,568 KB
testcase_08 AC 126 ms
53,032 KB
testcase_09 AC 129 ms
54,420 KB
testcase_10 AC 128 ms
54,108 KB
testcase_11 AC 129 ms
54,136 KB
testcase_12 AC 127 ms
53,892 KB
testcase_13 AC 129 ms
54,000 KB
testcase_14 AC 129 ms
54,268 KB
testcase_15 AC 127 ms
53,900 KB
testcase_16 AC 126 ms
54,328 KB
testcase_17 AC 124 ms
53,848 KB
testcase_18 AC 142 ms
56,880 KB
testcase_19 AC 142 ms
60,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder314;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long[] dp=new long[n+1];
		long mod=(long)Math.pow(10, 9)+7;
		dp[0]=0;///ケン・ケン・パ ケン・パ
		dp[1]=0;
		if(n==1){
			System.out.println(1);
			return;
		}
		dp[2]=1;
		if(n==2){
			System.out.println(2);
			return;
		}
		dp[3]=1;
		if(n==3){
			System.out.println(2);
			return;
		}
		for(int i=4;i<=n;i++){
			dp[i]=(dp[i-2]+dp[i-3])%mod;
		}
		System.out.println((dp[n]+dp[n-1]+dp[n-2])%mod);
	}
}
0