結果

問題 No.533 Mysterious Stairs
ユーザー tentententen
提出日時 2023-03-07 15:46:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 222 ms / 5,000 ms
コード長 2,083 bytes
コンパイル時間 4,631 ms
コンパイル使用メモリ 90,092 KB
実行使用メモリ 87,684 KB
最終ジャッジ日時 2023-10-18 05:31:02
合計ジャッジ時間 7,039 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,528 KB
testcase_01 AC 55 ms
52,532 KB
testcase_02 AC 54 ms
53,524 KB
testcase_03 AC 54 ms
53,516 KB
testcase_04 AC 54 ms
53,520 KB
testcase_05 AC 54 ms
53,520 KB
testcase_06 AC 55 ms
53,528 KB
testcase_07 AC 57 ms
53,520 KB
testcase_08 AC 56 ms
53,532 KB
testcase_09 AC 56 ms
53,528 KB
testcase_10 AC 56 ms
53,528 KB
testcase_11 AC 55 ms
53,528 KB
testcase_12 AC 54 ms
53,524 KB
testcase_13 AC 55 ms
53,516 KB
testcase_14 AC 55 ms
53,520 KB
testcase_15 AC 56 ms
52,560 KB
testcase_16 AC 56 ms
53,520 KB
testcase_17 AC 57 ms
52,564 KB
testcase_18 AC 58 ms
53,528 KB
testcase_19 AC 59 ms
53,528 KB
testcase_20 AC 77 ms
58,568 KB
testcase_21 AC 82 ms
58,780 KB
testcase_22 AC 120 ms
66,320 KB
testcase_23 AC 222 ms
87,684 KB
testcase_24 AC 222 ms
87,580 KB
testcase_25 AC 78 ms
59,120 KB
testcase_26 AC 217 ms
86,948 KB
testcase_27 AC 91 ms
63,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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[n + 10][3];
        dp[1][0] = 1;
        dp[2][1] = 1;
        dp[3][2] = 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[i + k + 1][k] += dp[i][j];
                    dp[i + k + 1][k] %= MOD;
                }
            }
        }
        int ans = 0;
        for (int x : dp[n]) {
            ans += x;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
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