結果

問題 No.1049 Zero (Exhaust)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-05-30 20:05:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 3,086 bytes
コンパイル時間 1,234 ms
コンパイル使用メモリ 105,852 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 13:45:13
合計ジャッジ時間 2,146 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 12 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 10 ms
6,940 KB
testcase_06 AC 17 ms
6,940 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 6 ms
6,940 KB
testcase_09 AC 13 ms
6,940 KB
testcase_10 AC 14 ms
6,944 KB
testcase_11 AC 14 ms
6,940 KB
testcase_12 AC 16 ms
6,940 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 9 ms
6,940 KB
testcase_15 AC 13 ms
6,944 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 11 ms
6,940 KB
testcase_18 AC 15 ms
6,944 KB
testcase_19 AC 12 ms
6,944 KB
testcase_20 AC 6 ms
6,944 KB
testcase_21 AC 13 ms
6,944 KB
testcase_22 AC 8 ms
6,944 KB
testcase_23 AC 17 ms
6,944 KB
testcase_24 AC 17 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif

template<int MOD> struct MInt {
  long long val;
  constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator-() const { return MInt(-val); }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt operator/(const MInt& n) const { return MInt(val) /= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  MInt& operator/=(const MInt& n) { val = (*this * n.inv()).val; return *this; }
  bool operator==(const MInt& n) { return val == n.val; }
  bool operator!=(const MInt& n) { return val != n.val; }
  MInt pow(long long n) const {
    MInt pow = val, ans = 1;
    for (long long p = n; p > 0; p >>= 1, pow *= pow)
      if (p & 1) ans *= pow;
    return ans;
  }
  MInt inv() const { return pow(MOD-2); }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
  friend istream& operator>>(istream& os, MInt& n) { os>>n.val; return os; }
};
constexpr int MOD = 1e9+7;
using mint = MInt<MOD>;

int main() {
  int P, K;
  ins(P, K);
  mint zeros = 1, nonzeros = 0;
  rep(i, K) {
    mint next_zeros = zeros * (P+1) + mint(2) * nonzeros,
         next_nonzeros = zeros * (P-1) + nonzeros * 2 * (P-1);
    swap(zeros, next_zeros);
    swap(nonzeros, next_nonzeros);
  }
  cout << zeros << endl;

  return 0;
}
0