結果

問題 No.1049 Zero (Exhaust)
ユーザー どららどらら
提出日時 2020-05-08 22:52:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,162 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 168,828 KB
実行使用メモリ 6,224 KB
最終ジャッジ日時 2023-09-17 03:20:16
合計ジャッジ時間 2,486 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,156 KB
testcase_01 AC 4 ms
6,224 KB
testcase_02 AC 5 ms
6,176 KB
testcase_03 AC 16 ms
5,980 KB
testcase_04 AC 4 ms
6,196 KB
testcase_05 AC 15 ms
6,100 KB
testcase_06 AC 23 ms
6,012 KB
testcase_07 AC 7 ms
6,112 KB
testcase_08 AC 11 ms
6,072 KB
testcase_09 AC 19 ms
6,148 KB
testcase_10 AC 20 ms
6,148 KB
testcase_11 AC 19 ms
5,976 KB
testcase_12 AC 20 ms
6,016 KB
testcase_13 AC 8 ms
5,976 KB
testcase_14 AC 12 ms
6,224 KB
testcase_15 AC 17 ms
6,164 KB
testcase_16 AC 14 ms
6,220 KB
testcase_17 AC 15 ms
6,016 KB
testcase_18 AC 19 ms
6,220 KB
testcase_19 AC 18 ms
6,012 KB
testcase_20 AC 10 ms
6,224 KB
testcase_21 AC 17 ms
5,980 KB
testcase_22 AC 12 ms
5,976 KB
testcase_23 AC 22 ms
6,224 KB
testcase_24 AC 22 ms
6,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(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 ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 200005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;

int main(){
  ll P, K;
  cin >> P >> K;
  
  mint x(1), y(0);
  rep(i,K){
    mint nx(0), ny(0);
    nx = x * (P + 1) + y * 2;
    ny = (x+y) * 2 * P - nx;
    x = nx;
    y = ny;
  }

  cout << x << endl;
  
  return 0;
}

0