結果

問題 No.314 ケンケンパ
ユーザー tentententen
提出日時 2024-02-05 15:49:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 235 ms / 1,000 ms
コード長 1,497 bytes
コンパイル時間 2,440 ms
コンパイル使用メモリ 80,068 KB
実行使用メモリ 88,580 KB
最終ジャッジ日時 2024-02-05 15:49:42
合計ジャッジ時間 5,424 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 211 ms
88,120 KB
testcase_01 AC 64 ms
54,632 KB
testcase_02 AC 63 ms
54,520 KB
testcase_03 AC 64 ms
54,636 KB
testcase_04 AC 64 ms
54,388 KB
testcase_05 AC 64 ms
54,776 KB
testcase_06 AC 63 ms
54,496 KB
testcase_07 AC 96 ms
54,508 KB
testcase_08 AC 63 ms
54,516 KB
testcase_09 AC 64 ms
54,752 KB
testcase_10 AC 63 ms
54,500 KB
testcase_11 AC 66 ms
54,648 KB
testcase_12 AC 63 ms
54,508 KB
testcase_13 AC 64 ms
54,668 KB
testcase_14 AC 66 ms
54,752 KB
testcase_15 AC 76 ms
54,624 KB
testcase_16 AC 67 ms
54,756 KB
testcase_17 AC 75 ms
56,980 KB
testcase_18 AC 124 ms
70,976 KB
testcase_19 AC 235 ms
88,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
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 + 1][3];
        dp[0][2] = 1;
        for (int i = 1; i <= n; i++) {
            dp[i][0] = dp[i - 1][2];
            dp[i][1] = dp[i - 1][0];
            dp[i][2] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        }
        long ans = Arrays.stream(dp[n]).reduce(0, (a, b) -> (a + b) % MOD);
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0