結果

問題 No.1049 Zero (Exhaust)
ユーザー rnanornano
提出日時 2023-07-05 01:08:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 2,659 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 166,872 KB
実行使用メモリ 19,212 KB
最終ジャッジ日時 2023-09-26 00:02:24
合計ジャッジ時間 9,098 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
18,984 KB
testcase_01 AC 7 ms
19,056 KB
testcase_02 AC 7 ms
19,212 KB
testcase_03 AC 305 ms
19,100 KB
testcase_04 AC 7 ms
19,068 KB
testcase_05 AC 248 ms
18,952 KB
testcase_06 AC 461 ms
19,056 KB
testcase_07 AC 53 ms
18,996 KB
testcase_08 AC 126 ms
19,064 KB
testcase_09 AC 338 ms
19,120 KB
testcase_10 AC 370 ms
19,044 KB
testcase_11 AC 371 ms
18,984 KB
testcase_12 AC 432 ms
18,996 KB
testcase_13 AC 91 ms
19,212 KB
testcase_14 AC 186 ms
18,996 KB
testcase_15 AC 314 ms
18,996 KB
testcase_16 AC 250 ms
19,064 KB
testcase_17 AC 263 ms
19,004 KB
testcase_18 AC 381 ms
19,064 KB
testcase_19 AC 318 ms
18,996 KB
testcase_20 AC 125 ms
19,060 KB
testcase_21 AC 327 ms
18,940 KB
testcase_22 AC 178 ms
18,984 KB
testcase_23 AC 457 ms
18,936 KB
testcase_24 AC 460 ms
18,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n-1); i >= 0; --i)
#define Rep(i,a,b) for (int i = a; i < b; ++i)
#define rRep(i,a,b) for (int i = a; i > b; --i)
#define fore(i,a) for(auto &i:a)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define Bit(x,i) (((x)>>(i))&1)
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
struct settings{settings(){ios_base::sync_with_stdio(0); cin.tie(0); cout<<fixed<<setprecision(15);};}settingss;
const double PI = acos(-1);
const int INF = 1001001001;
const ll LINF = 1001001001001001001LL;

const int mod = 1000000007;
class modint {
  long long x;
public:
  modint(long long x=0) : x((x%mod+mod)%mod) {}
  modint operator-() const {
    return modint(-x);
  }
  modint& operator+=(const modint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator-=(const modint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator*=(const  modint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint operator+(const modint& a) const {
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint& a) const {
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint& a) const {
    modint res(*this);
    return res*=a;
  }
  modint pow(ll t) const {
    if (!t) return 1;
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  modint inv() const {
    return pow(mod-2);
  }
  modint& operator/=(const modint& a) {
    return (*this) *= a.inv();
  }
  modint operator/(const modint& a) const {
    modint res(*this);
    return res/=a;
  }
  friend ostream& operator<<(ostream& os, const modint& m){
    os << m.x;
    return os;
  }
};

ll powmod(ll n, ll p, ll m) {
  if(p == 0) return 1;
  ll res = powmod(n, p/2, m);
  n %= m;
  if(p%2 == 0) return (res*res) % m;
  return (((res*res) % m)*n) % m;
}

modint dp[1000100][2];

int main() {
  ll P, K; cin >> P >> K;
  dp[0][0] = 1;
  rep(i, K) {
    dp[i+1][0] += dp[i][1] * 2 + dp[i][0] * (P+1);
    dp[i+1][1] = powmod(P*2, i+1, mod);
    dp[i+1][1] -= dp[i+1][0];
  }
  cout << dp[K][0] << endl;
}
0