結果
問題 |
No.1049 Zero (Exhaust)
|
ユーザー |
![]() |
提出日時 | 2020-05-09 10:54:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,991 bytes |
コンパイル時間 | 1,456 ms |
コンパイル使用メモリ | 169,380 KB |
実行使用メモリ | 11,176 KB |
最終ジャッジ日時 | 2024-07-05 07:34:19 |
合計ジャッジ時間 | 2,446 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#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; }