結果

問題 No.533 Mysterious Stairs
ユーザー tentententen
提出日時 2023-01-06 18:44:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,934 ms / 5,000 ms
コード長 2,174 bytes
コンパイル時間 2,740 ms
コンパイル使用メモリ 94,448 KB
実行使用メモリ 86,188 KB
最終ジャッジ日時 2024-05-07 18:46:42
合計ジャッジ時間 11,093 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,464 KB
testcase_01 AC 55 ms
36,948 KB
testcase_02 AC 54 ms
37,224 KB
testcase_03 AC 53 ms
37,288 KB
testcase_04 AC 54 ms
37,052 KB
testcase_05 AC 55 ms
37,212 KB
testcase_06 AC 53 ms
37,100 KB
testcase_07 AC 52 ms
37,360 KB
testcase_08 AC 55 ms
37,204 KB
testcase_09 AC 54 ms
36,944 KB
testcase_10 AC 55 ms
37,292 KB
testcase_11 AC 55 ms
37,068 KB
testcase_12 AC 54 ms
37,296 KB
testcase_13 AC 55 ms
36,944 KB
testcase_14 AC 54 ms
37,108 KB
testcase_15 AC 56 ms
37,244 KB
testcase_16 AC 56 ms
37,216 KB
testcase_17 AC 59 ms
37,424 KB
testcase_18 AC 62 ms
37,660 KB
testcase_19 AC 64 ms
37,916 KB
testcase_20 AC 95 ms
49,128 KB
testcase_21 AC 95 ms
50,004 KB
testcase_22 AC 238 ms
67,176 KB
testcase_23 AC 1,934 ms
86,188 KB
testcase_24 AC 1,677 ms
84,620 KB
testcase_25 AC 93 ms
49,136 KB
testcase_26 AC 1,888 ms
83,568 KB
testcase_27 AC 142 ms
55,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0