結果
問題 | No.1049 Zero (Exhaust) |
ユーザー |
|
提出日時 | 2020-05-08 21:46:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 2,093 bytes |
コンパイル時間 | 1,642 ms |
コンパイル使用メモリ | 171,152 KB |
実行使用メモリ | 57,976 KB |
最終ジャッジ日時 | 2024-07-04 00:24:23 |
合計ジャッジ時間 | 3,236 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef long double ld;#define rep(i,n) for (int i = 0; i < (n); ++i)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; }const ll INF=1LL<<60;const int inf=(1<<30)-1;const int mod=1e9+7;int dx[4]={1,0,-1,0};int dy[4]={0,1,0,-1};class mint{public:long long x;constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}constexpr mint operator-() const{return mint(-x);}constexpr mint& operator+=(const mint& a){if((x += a.x) >= mod) x -= mod;return *this;}constexpr mint& operator-=(const mint& a){if((x += mod-a.x) >= mod) x -= mod;return *this;}constexpr mint& operator*=(const mint& a){(x *= a.x) %= mod;return *this;}constexpr mint operator+(const mint& a) const{mint res(*this);return res+=a;}constexpr mint operator-(const mint& a) const{mint res(*this);return res-=a;}constexpr mint operator*(const mint& a) const{mint res(*this);return res*=a;}constexpr mint pow(long long x) const{if(!x) return 1;mint a = pow(x>>1);a *= a;if(x&1) a *= *this;return a;}constexpr mint inv() const{return pow(mod-2);}constexpr mint& operator/=(const mint& a){return (*this) *= a.inv();}constexpr mint operator/(const mint& a) const{mint res(*this);return res/=a;}friend ostream& operator<<(ostream& os, const mint& m){os << m.x; return os;}};int main(){cin.tie(0);ios::sync_with_stdio(false);ll P,k;cin >> P >> k;vector<vector<mint>> dp(k+1,vector<mint>(2));dp[0][0]=1;mint p=P;rep(i,k){dp[i+1][0]=dp[i][0]*(p+1)+dp[i][1]*2;dp[i+1][1]=dp[i][0]*(p-1)+dp[i][1]*(p+p-2);}cout << dp[k][0] << endl;}