結果

問題 No.1181 Product Sum for All Subsets
ユーザー Rho
提出日時 2020-08-21 21:42:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 166,868 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-10-15 05:27:18
合計ジャッジ時間 3,802 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
#define vi vector<ll>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=1000000007;
ll kj[200006],kji[200006];
ll modpow(ll a,ll x){
  ll res=1;
  while(x){
    if(x&1)res=res*a%mod;
    a=a*a%mod;
    x>>=1;
  }
  return res;
}
void setkj(){
  ll maxA=200000;
  kj[0]=1;
  rep(i,maxA)kj[i+1]=kj[i]*(i+1)%mod;
  rep(i,maxA+1)kji[i]=modpow(kj[i],mod-2);
}
ll comb(ll r,ll c){
  return kj[r]*kji[c]%mod*kji[r-c]%mod;
}

signed main(){
  setkj();
  ll n,k;cin>>n>>k;
  k%=mod;
  ll m=k*(k+1)/2%mod;
  ll ans=0;
  rep(i,n){
    ans+=comb(n,i)*modpow(m,i)%mod*modpow(k,n-i);
    ans%=mod;
  }
  cout<<ans<<endl;
}
0