結果

問題 No.533 Mysterious Stairs
ユーザー tentententen
提出日時 2022-08-10 17:11:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 1,542 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 78,216 KB
実行使用メモリ 64,344 KB
最終ジャッジ日時 2023-10-21 02:53:06
合計ジャッジ時間 5,787 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
52,524 KB
testcase_01 AC 60 ms
53,436 KB
testcase_02 AC 60 ms
52,256 KB
testcase_03 AC 56 ms
52,272 KB
testcase_04 AC 56 ms
52,520 KB
testcase_05 AC 56 ms
53,424 KB
testcase_06 AC 56 ms
52,504 KB
testcase_07 AC 55 ms
53,424 KB
testcase_08 AC 56 ms
53,432 KB
testcase_09 AC 58 ms
53,428 KB
testcase_10 AC 57 ms
53,424 KB
testcase_11 AC 56 ms
53,432 KB
testcase_12 AC 56 ms
52,528 KB
testcase_13 AC 55 ms
53,432 KB
testcase_14 AC 56 ms
52,492 KB
testcase_15 AC 58 ms
53,424 KB
testcase_16 AC 57 ms
53,428 KB
testcase_17 AC 59 ms
53,432 KB
testcase_18 AC 63 ms
53,436 KB
testcase_19 AC 61 ms
53,424 KB
testcase_20 AC 95 ms
55,180 KB
testcase_21 AC 99 ms
54,780 KB
testcase_22 AC 102 ms
59,028 KB
testcase_23 AC 104 ms
63,028 KB
testcase_24 AC 103 ms
62,984 KB
testcase_25 AC 78 ms
54,184 KB
testcase_26 AC 130 ms
64,344 KB
testcase_27 AC 91 ms
55,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[][] dp = new int[3][n + 3];
        dp[0][1] = 1;
        dp[1][2] = 1;
        dp[2][3] = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (j == k) {
                        continue;
                    }
                    dp[k][i + k + 1] += dp[j][i];
                    dp[k][i + k + 1] %= MOD;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < 3; i++) {
            ans += dp[i][n];
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0