結果

問題 No.533 Mysterious Stairs
ユーザー uafr_csuafr_cs
提出日時 2017-06-23 23:13:47
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 958 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 78,248 KB
実行使用メモリ 80,516 KB
最終ジャッジ日時 2024-04-15 01:05:27
合計ジャッジ時間 6,849 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 117 ms
40,580 KB
testcase_03 AC 110 ms
40,280 KB
testcase_04 AC 122 ms
41,224 KB
testcase_05 AC 124 ms
41,176 KB
testcase_06 AC 116 ms
41,048 KB
testcase_07 AC 127 ms
41,428 KB
testcase_08 AC 117 ms
40,984 KB
testcase_09 AC 126 ms
41,584 KB
testcase_10 AC 116 ms
41,344 KB
testcase_11 AC 120 ms
41,428 KB
testcase_12 AC 119 ms
41,112 KB
testcase_13 AC 119 ms
41,316 KB
testcase_14 AC 117 ms
40,984 KB
testcase_15 AC 122 ms
41,332 KB
testcase_16 AC 119 ms
41,008 KB
testcase_17 AC 124 ms
41,248 KB
testcase_18 AC 124 ms
41,388 KB
testcase_19 AC 129 ms
41,472 KB
testcase_20 AC 139 ms
47,296 KB
testcase_21 AC 139 ms
47,180 KB
testcase_22 AC 175 ms
53,464 KB
testcase_23 AC 250 ms
73,080 KB
testcase_24 AC 249 ms
80,516 KB
testcase_25 AC 137 ms
46,472 KB
testcase_26 AC 234 ms
68,444 KB
testcase_27 AC 145 ms
49,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		long[][] DP = new long[4][N + 1];
		DP[1][1] = 1;
		DP[2][2] = 1;
		DP[3][3] = 1;
		
		for(int pos = 1; pos < N; pos++){
			for(int prev_step = 1; prev_step <= 3; prev_step++){
				for(int step = 1; step <= 3; step++){
					if(prev_step == step){ continue; }
					
					final int next_pos = pos + step;
					if(next_pos > N){ break; }
					
					DP[step][next_pos] += DP[prev_step][pos];
					DP[step][next_pos] %= MOD;
				}
			}
		}
		
		long sum = 0;
		for(int i = 1; i <= 3; i++){
			sum += DP[i][N];
			sum %= MOD;
		}
		
		System.out.println(sum);
	}
}
0