結果

問題 No.1049 Zero (Exhaust)
ユーザー silviasetitech
提出日時 2020-05-10 09:34:07
言語 Java
(openjdk 23)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 1,727 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 78,132 KB
実行使用メモリ 108,816 KB
最終ジャッジ日時 2024-07-07 04:55:52
合計ジャッジ時間 9,852 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        No1049ZeroExhaust solver = new No1049ZeroExhaust();
        solver.solve(1, in, out);
        out.close();
    }

    static class No1049ZeroExhaust {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int p = in.nextInt();
            int k = in.nextInt();
            ModInt[] z = new ModInt[k + 1];
            ModInt[] nz = new ModInt[k + 1];
            z[0] = new ModInt(1);
            nz[0] = new ModInt(0);
            for (int i = 0; i < k; i++) {
                z[i + 1] = z[i].mul(p + 1).add(nz[i].mul(2));
                nz[i + 1] = z[i].mul(p - 1).add(nz[i].mul(2 * p - 2));
            }
            out.println(z[k].getVal());

        }

    }

    static class ModInt {
        public long val;
        final int MOD = (int) 1e9 + 7;

        public ModInt(long i) {
            this.val = (i + MOD) % MOD;
        }

        public ModInt mul(long l) {
            return new ModInt(this.val * l);
        }

        public ModInt add(ModInt m) {
            return new ModInt(this.val + m.val);
        }

        public long getVal() {
            return val;
        }

        public String toString() {
            return Long.toString(val);
        }

    }
}

0