結果

問題 No.533 Mysterious Stairs
ユーザー tentententen
提出日時 2021-12-02 09:31:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 199 ms / 5,000 ms
コード長 1,410 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 74,124 KB
実行使用メモリ 84,320 KB
最終ジャッジ日時 2023-09-18 10:11:00
合計ジャッジ時間 5,382 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,752 KB
testcase_01 AC 44 ms
49,356 KB
testcase_02 AC 45 ms
49,404 KB
testcase_03 AC 45 ms
49,428 KB
testcase_04 AC 47 ms
49,468 KB
testcase_05 AC 45 ms
49,456 KB
testcase_06 AC 45 ms
49,648 KB
testcase_07 AC 45 ms
49,580 KB
testcase_08 AC 46 ms
49,388 KB
testcase_09 AC 45 ms
49,568 KB
testcase_10 AC 45 ms
49,492 KB
testcase_11 AC 49 ms
49,484 KB
testcase_12 AC 45 ms
49,688 KB
testcase_13 AC 44 ms
49,340 KB
testcase_14 AC 45 ms
49,424 KB
testcase_15 AC 44 ms
49,344 KB
testcase_16 AC 45 ms
49,344 KB
testcase_17 AC 46 ms
49,352 KB
testcase_18 AC 46 ms
47,328 KB
testcase_19 AC 47 ms
49,360 KB
testcase_20 AC 70 ms
55,212 KB
testcase_21 AC 68 ms
55,232 KB
testcase_22 AC 110 ms
63,908 KB
testcase_23 AC 199 ms
84,320 KB
testcase_24 AC 198 ms
84,264 KB
testcase_25 AC 68 ms
55,168 KB
testcase_26 AC 195 ms
83,988 KB
testcase_27 AC 82 ms
57,584 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[Math.max(4, n + 1)][3];
        dp[1][0] = 1;
        dp[2][1] = 1;
        dp[3][0] = 1;
        dp[3][1] = 1;
        dp[3][2] = 1;
        for (int i = 4; i <= n; i++) {
            dp[i][0] = (dp[i - 1][1] + dp[i - 1][2]) % MOD;
            dp[i][1] = (dp[i - 2][0] + dp[i - 2][2]) % MOD;
            dp[i][2] = (dp[i - 3][0] + dp[i - 3][1]) % MOD;
        }
        int ans = ((dp[n][0] + dp[n][1]) % MOD + dp[n][2]) % 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 {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0