結果

問題 No.533 Mysterious Stairs
ユーザー tentententen
提出日時 2021-11-02 14:09:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 1,519 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 77,828 KB
実行使用メモリ 61,896 KB
最終ジャッジ日時 2024-04-19 21:07:00
合計ジャッジ時間 5,252 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
49,964 KB
testcase_01 AC 50 ms
49,948 KB
testcase_02 AC 48 ms
50,048 KB
testcase_03 AC 49 ms
50,472 KB
testcase_04 AC 50 ms
50,080 KB
testcase_05 AC 49 ms
50,044 KB
testcase_06 AC 49 ms
50,312 KB
testcase_07 AC 50 ms
50,136 KB
testcase_08 AC 50 ms
50,312 KB
testcase_09 AC 49 ms
50,056 KB
testcase_10 AC 50 ms
50,328 KB
testcase_11 AC 50 ms
49,904 KB
testcase_12 AC 49 ms
50,380 KB
testcase_13 AC 50 ms
49,980 KB
testcase_14 AC 50 ms
50,060 KB
testcase_15 AC 50 ms
50,176 KB
testcase_16 AC 51 ms
50,328 KB
testcase_17 AC 52 ms
50,472 KB
testcase_18 AC 53 ms
50,216 KB
testcase_19 AC 54 ms
50,024 KB
testcase_20 AC 74 ms
51,680 KB
testcase_21 AC 68 ms
51,296 KB
testcase_22 AC 93 ms
56,756 KB
testcase_23 AC 94 ms
59,740 KB
testcase_24 AC 115 ms
61,896 KB
testcase_25 AC 68 ms
51,360 KB
testcase_26 AC 139 ms
61,852 KB
testcase_27 AC 75 ms
53,332 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 + 10];
        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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0