結果

問題 No.1049 Zero (Exhaust)
ユーザー hanyuhanyu
提出日時 2020-05-08 22:13:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 172,408 KB
実行使用メモリ 57,944 KB
最終ジャッジ日時 2024-07-04 00:50:15
合計ジャッジ時間 3,446 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll p, k;
  cin >> p >> k;
  
  vector<vector<ll>> x(k + 1, vector<ll>(2, 0));
  x.at(0).at(0) = 1;
  for (int i = 0; i < k; i++) {
    // add
    x.at(i + 1).at(0) += x.at(i).at(0) + x.at(i).at(1);
    x.at(i + 1).at(1) += (x.at(i).at(0) + x.at(i).at(1)) * (p - 1);
    // multiple
    x.at(i + 1).at(0) += x.at(i).at(0) * p + x.at(i).at(1);
    x.at(i + 1).at(1) += x.at(i).at(1) * (p - 1);
    
    x.at(i + 1).at(0) %= MOD;
    x.at(i + 1).at(1) %= MOD;
  }
  
  cout << x.at(k).at(0) << '\n';
}
0