結果

問題 No.1049 Zero (Exhaust)
ユーザー htensaihtensai
提出日時 2020-05-15 08:24:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 2,900 ms
コンパイル使用メモリ 74,140 KB
実行使用メモリ 57,840 KB
最終ジャッジ日時 2023-10-17 14:37:09
合計ジャッジ時間 8,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
57,256 KB
testcase_01 AC 143 ms
57,668 KB
testcase_02 AC 142 ms
57,128 KB
testcase_03 AC 155 ms
57,108 KB
testcase_04 AC 144 ms
57,628 KB
testcase_05 AC 153 ms
57,352 KB
testcase_06 AC 157 ms
57,576 KB
testcase_07 AC 152 ms
57,112 KB
testcase_08 AC 153 ms
57,748 KB
testcase_09 AC 154 ms
57,656 KB
testcase_10 AC 156 ms
57,504 KB
testcase_11 AC 156 ms
57,100 KB
testcase_12 AC 156 ms
57,732 KB
testcase_13 AC 150 ms
57,616 KB
testcase_14 AC 153 ms
57,840 KB
testcase_15 AC 154 ms
57,568 KB
testcase_16 AC 150 ms
57,132 KB
testcase_17 AC 156 ms
57,692 KB
testcase_18 AC 153 ms
57,544 KB
testcase_19 AC 154 ms
55,476 KB
testcase_20 AC 149 ms
57,436 KB
testcase_21 AC 152 ms
57,100 KB
testcase_22 AC 153 ms
57,144 KB
testcase_23 AC 157 ms
57,620 KB
testcase_24 AC 155 ms
57,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        int k = sc.nextInt();
        long prevZero = 1;
        long prevNotZero = 0;
        for (int i = 0; i < k; i++) {
            long nextZero = (prevZero * (p + 1) + prevNotZero * 2) % MOD;;
            long nextNotZero = (prevZero * (p - 1) + prevNotZero * (2 * p - 2)) % MOD;
            prevZero = nextZero;
            prevNotZero = nextNotZero;
        }
        System.out.println(prevZero);
    }
}
0