結果

問題 No.533 Mysterious Stairs
ユーザー tentententen
提出日時 2023-11-15 17:01:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 219 ms / 5,000 ms
コード長 2,047 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 89,956 KB
実行使用メモリ 89,596 KB
最終ジャッジ日時 2023-11-15 17:01:58
合計ジャッジ時間 5,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
54,000 KB
testcase_01 AC 54 ms
52,000 KB
testcase_02 AC 51 ms
54,004 KB
testcase_03 AC 51 ms
54,016 KB
testcase_04 AC 54 ms
54,004 KB
testcase_05 AC 52 ms
53,992 KB
testcase_06 AC 54 ms
54,004 KB
testcase_07 AC 52 ms
53,992 KB
testcase_08 AC 54 ms
53,992 KB
testcase_09 AC 52 ms
53,992 KB
testcase_10 AC 51 ms
54,000 KB
testcase_11 AC 52 ms
53,988 KB
testcase_12 AC 52 ms
53,996 KB
testcase_13 AC 52 ms
53,996 KB
testcase_14 AC 52 ms
53,988 KB
testcase_15 AC 53 ms
53,984 KB
testcase_16 AC 53 ms
53,980 KB
testcase_17 AC 53 ms
53,996 KB
testcase_18 AC 54 ms
54,000 KB
testcase_19 AC 53 ms
53,992 KB
testcase_20 AC 97 ms
60,608 KB
testcase_21 AC 98 ms
60,684 KB
testcase_22 AC 128 ms
68,356 KB
testcase_23 AC 214 ms
89,468 KB
testcase_24 AC 219 ms
89,596 KB
testcase_25 AC 97 ms
60,668 KB
testcase_26 AC 208 ms
88,948 KB
testcase_27 AC 98 ms
65,132 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 + 5][3];
        dp[1][0] = 1;
        dp[2][1] = 1;
        dp[3][2] = 1;
        for (int i = 1; i < n; i++) {
            dp[i + 1][0] += (dp[i][1] + dp[i][2]) % MOD;
            dp[i + 1][0] %= MOD;
            dp[i + 2][1] += (dp[i][0] + dp[i][2]) % MOD;
            dp[i + 2][1] %= MOD;
            dp[i + 3][2] += (dp[i][0] + dp[i][1]) % MOD;
            dp[i + 3][2] %= MOD;
        }
        int sum = 0;
        for (int x : dp[n]) {
            sum += x;
            sum %= MOD;
        }
        System.out.println(sum);
    }
}
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