結果

問題 No.1049 Zero (Exhaust)
ユーザー kya_skikya_ski
提出日時 2020-05-09 10:54:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,991 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 166,192 KB
実行使用メモリ 11,184 KB
最終ジャッジ日時 2023-09-18 17:27:52
合計ジャッジ時間 2,902 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 9 ms
8,616 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 9 ms
7,612 KB
testcase_06 AC 14 ms
11,184 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 6 ms
5,660 KB
testcase_09 AC 11 ms
9,092 KB
testcase_10 AC 12 ms
9,612 KB
testcase_11 AC 12 ms
9,648 KB
testcase_12 AC 12 ms
10,716 KB
testcase_13 AC 5 ms
4,940 KB
testcase_14 AC 7 ms
6,628 KB
testcase_15 AC 10 ms
8,820 KB
testcase_16 AC 9 ms
7,636 KB
testcase_17 AC 9 ms
7,944 KB
testcase_18 AC 12 ms
9,836 KB
testcase_19 AC 10 ms
8,788 KB
testcase_20 AC 6 ms
5,484 KB
testcase_21 AC 10 ms
8,992 KB
testcase_22 AC 7 ms
6,488 KB
testcase_23 AC 14 ms
11,088 KB
testcase_24 AC 13 ms
11,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int MOD = 1000000007;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
	int p, k;
	cin >> p >> k;
	
	ModInt<MOD> dp[k + 1][2];
	dp[0][0] = 1;
	
	for (int i = 0; i < k; i++) {
		dp[i + 1][0] = dp[i][0] * (p + 1) + dp[i][1] * 2;
		dp[i + 1][1] = dp[i][0] * (p - 1) + dp[i][1] * (2 * p - 2);
	}
	
	cout << dp[k][0] << '\n';
	
	return 0;
}
0