結果

問題 No.1049 Zero (Exhaust)
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-05-09 14:35:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,612 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 167,672 KB
実行使用メモリ 19,300 KB
最終ジャッジ日時 2023-09-19 06:22:35
合計ジャッジ時間 3,396 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,300 KB
testcase_01 AC 7 ms
19,044 KB
testcase_02 AC 7 ms
19,060 KB
testcase_03 AC 16 ms
18,992 KB
testcase_04 AC 7 ms
19,176 KB
testcase_05 AC 15 ms
19,040 KB
testcase_06 AC 20 ms
19,056 KB
testcase_07 AC 9 ms
19,112 KB
testcase_08 AC 11 ms
19,176 KB
testcase_09 AC 17 ms
18,964 KB
testcase_10 AC 18 ms
19,260 KB
testcase_11 AC 18 ms
18,968 KB
testcase_12 AC 19 ms
19,044 KB
testcase_13 AC 10 ms
19,040 KB
testcase_14 AC 13 ms
19,108 KB
testcase_15 AC 16 ms
18,976 KB
testcase_16 AC 14 ms
19,112 KB
testcase_17 AC 15 ms
19,120 KB
testcase_18 AC 18 ms
18,964 KB
testcase_19 AC 16 ms
18,988 KB
testcase_20 AC 11 ms
18,996 KB
testcase_21 AC 16 ms
18,996 KB
testcase_22 AC 13 ms
19,040 KB
testcase_23 AC 20 ms
19,036 KB
testcase_24 AC 20 ms
18,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for(int i = (int)(n)-1; i >= 0; --i)
#define whole(x) (x).begin(), (x).end()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ld = long double;
constexpr int INF = 1LL<<60;
constexpr long long LINF = 1LL<<60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

constexpr int MOD = 1e9+7;
//constexpr int MOD = 998244353;

struct mint {
long long x;
  mint(long long x = 0) noexcept : x((x%MOD + MOD) % MOD) {}

  // basis
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) noexcept { if((x += a.x) >= MOD) x -= MOD; return *this; }
  mint& operator-=(const mint a) noexcept { if((x += MOD-a.x) >= MOD) x -= MOD; return *this; }
  mint& operator*=(const mint a) noexcept { (x *= a.x) %= MOD; return *this; }
  mint operator+(const mint a) const noexcept { return mint(*this) += a; }
  mint operator-(const mint a) const noexcept { return mint(*this) -= a; }
  mint operator*(const mint a) const noexcept { return mint(*this) *= a; }
  mint mpow(long long t) const noexcept {
    if(!t) return 1;
    mint a = mpow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const noexcept { return mpow(MOD-2); }
  mint& operator/=(const mint a) noexcept { return *this *= a.inv(); }
  mint operator/(const mint a) const noexcept { return mint(*this) /= a; }

  // comparison
  bool operator==(const mint &a) const noexcept { return this->x == a.x; }
  bool operator!=(const mint &a) const noexcept { return this->x != a.x; }

  // I/O stream
  friend istream& operator>>(istream& is, mint& a) noexcept { return is >> a.x; }
  friend ostream& operator<<(ostream& os, const mint& a) noexcept { return os << a.x; }
};
// additional
mint mpow(const long long &a, long long n) noexcept { return mint(a).mpow(n); }
mint mpow(const mint &a, long long n) noexcept { return a.mpow(n); }


int p, k;
mint dp[1000100][2];

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> p >> k;
  dp[0][0] = 1;
  rep(i, k) {
    dp[i+1][0] += dp[i][1]+dp[i][0]+dp[i][0]*p+dp[i][1];
    dp[i+1][1] += dp[i][0]*(p-1)+dp[i][1]*(p-1)+dp[i][1]*(p-1);
  }
  cout << dp[k][0] << '\n';
  return 0;
}
0