結果
| 問題 | No.1049 Zero (Exhaust) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-05-09 01:39:46 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 22 ms / 2,000 ms | 
| コード長 | 1,476 bytes | 
| コンパイル時間 | 2,445 ms | 
| コンパイル使用メモリ | 192,636 KB | 
| 最終ジャッジ日時 | 2025-01-10 09:31:03 | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         int p,k; scanf("%d%d",&p,&k);
      |                  ~~~~~^~~~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }
	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }
	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}
	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};
mint operator+(long long x,const mint& m){ return m+x; }
mint operator*(long long x,const mint& m){ return m*x; }
int main(){
	int p,k; scanf("%d%d",&p,&k);
	mint dp[1000001][2];
	dp[0][0]=1;
	rep(i,k){
		dp[i+1][0]=(p+1)*dp[i][0]+2*dp[i][1];
		dp[i+1][1]=(p-1)*dp[i][0]+(2*p-2)*dp[i][1];
	}
	printf("%d\n",dp[k][0].to_int());
	return 0;
}
            
            
            
        