結果

問題 No.1049 Zero (Exhaust)
ユーザー chocono2230chocono2230
提出日時 2020-05-08 22:51:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 2,015 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 169,888 KB
実行使用メモリ 57,972 KB
最終ジャッジ日時 2023-09-17 03:18:26
合計ジャッジ時間 3,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 62 ms
40,312 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 52 ms
33,436 KB
testcase_06 AC 90 ms
57,972 KB
testcase_07 AC 13 ms
10,020 KB
testcase_08 AC 28 ms
19,292 KB
testcase_09 AC 69 ms
43,996 KB
testcase_10 AC 75 ms
47,556 KB
testcase_11 AC 75 ms
47,960 KB
testcase_12 AC 86 ms
54,896 KB
testcase_13 AC 22 ms
14,640 KB
testcase_14 AC 41 ms
26,260 KB
testcase_15 AC 64 ms
41,164 KB
testcase_16 AC 52 ms
33,900 KB
testcase_17 AC 55 ms
35,296 KB
testcase_18 AC 76 ms
48,680 KB
testcase_19 AC 66 ms
41,480 KB
testcase_20 AC 27 ms
18,956 KB
testcase_21 AC 66 ms
42,808 KB
testcase_22 AC 38 ms
25,272 KB
testcase_23 AC 92 ms
57,728 KB
testcase_24 AC 90 ms
57,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  ll p, k;
  cin >> p >> k;
  vector<vector<mint>> dp(k+1, vector<mint>(2));
  dp.at(0).at(0) = 1;
  dp.at(0).at(1) = 0;
  rep(i, k){
    dp.at(i+1).at(0) = dp.at(i).at(0) * (p + 1);
    dp.at(i+1).at(1) = dp.at(i).at(0) * (p - 1);
    dp.at(i+1).at(0) += dp.at(i).at(1) * 2;
    dp.at(i+1).at(1) += dp.at(i).at(1) * 2 * (p - 1);
  }
  mint ans = dp.at(k).at(0);
  cout << ans.x << endl;
  return 0;
}
0