結果

問題 No.314 ケンケンパ
ユーザー めうめう🎒めうめう🎒
提出日時 2016-05-06 16:44:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 425 ms / 1,000 ms
コード長 738 bytes
コンパイル時間 2,549 ms
コンパイル使用メモリ 77,176 KB
実行使用メモリ 116,160 KB
最終ジャッジ日時 2024-04-15 13:32:39
合計ジャッジ時間 9,716 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 425 ms
115,756 KB
testcase_01 AC 291 ms
84,572 KB
testcase_02 AC 313 ms
84,820 KB
testcase_03 AC 284 ms
84,728 KB
testcase_04 AC 307 ms
84,772 KB
testcase_05 AC 281 ms
84,844 KB
testcase_06 AC 286 ms
84,732 KB
testcase_07 AC 297 ms
84,700 KB
testcase_08 AC 296 ms
84,520 KB
testcase_09 AC 281 ms
84,792 KB
testcase_10 AC 280 ms
84,800 KB
testcase_11 AC 280 ms
84,616 KB
testcase_12 AC 277 ms
84,744 KB
testcase_13 AC 283 ms
84,636 KB
testcase_14 AC 296 ms
85,176 KB
testcase_15 AC 299 ms
85,240 KB
testcase_16 AC 302 ms
85,900 KB
testcase_17 AC 321 ms
87,856 KB
testcase_18 AC 355 ms
99,900 KB
testcase_19 AC 413 ms
116,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.Arrays;

class Main{
	static int n;

	static long memo[][] = new long[1000010][3];

	static long saiki(int now,int how_ken){
		if(now == n) return 1;
		if(memo[now][how_ken] != -1) return memo[now][how_ken];
		long sum = 0;
		if(how_ken == 0){
			sum += saiki(now + 1,1);
		}else if(how_ken == 2){
			sum += saiki(now + 1,0);
		}else{
			sum += saiki(now + 1,how_ken + 1);
			sum += saiki(now + 1,0);
		}
		return memo[now][how_ken] = sum % 1000000007;
	}

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(int i = 0;i < 1000010;i++){
			for(int j = 0;j < 3;j++){
				memo[i][j] = -1;
			}
		}
		System.out.println(saiki(0,0) % 1000000007);
	}
}
0