結果

問題 No.391 CODING WAR
ユーザー kzyKTkzyKT
提出日時 2016-07-08 23:16:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 2,129 bytes
コンパイル時間 1,606 ms
コンパイル使用メモリ 159,952 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-04-21 07:55:52
合計ジャッジ時間 3,678 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
34,688 KB
testcase_01 AC 38 ms
34,460 KB
testcase_02 AC 51 ms
34,560 KB
testcase_03 AC 38 ms
34,432 KB
testcase_04 AC 40 ms
34,552 KB
testcase_05 AC 46 ms
34,560 KB
testcase_06 AC 38 ms
34,560 KB
testcase_07 AC 38 ms
34,560 KB
testcase_08 AC 39 ms
34,560 KB
testcase_09 AC 117 ms
34,432 KB
testcase_10 AC 100 ms
34,560 KB
testcase_11 AC 69 ms
34,592 KB
testcase_12 AC 39 ms
34,560 KB
testcase_13 AC 101 ms
34,560 KB
testcase_14 AC 97 ms
34,560 KB
testcase_15 AC 109 ms
34,560 KB
testcase_16 AC 81 ms
34,560 KB
testcase_17 AC 89 ms
34,432 KB
testcase_18 AC 73 ms
34,648 KB
testcase_19 AC 74 ms
34,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;
  r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){
    q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;
    r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;
  }
  *c=r0;*a=a0;*b=b0;
}
ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}
ll fact[2000100],fact_inv[2000100];
ll nCr(ll N, ll K){
  if(K<0||K>N) return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}
ll nHr(ll N, ll K){
  if(N==0 && K==0) return 1;
  if(N==0) return 0;
  return nCr(N+K-1, K);
}
void init() {
  fact[0]=1;
  REP(i,1,2000100) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  for(int i=2000050-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}
ll mod_pow(ll x,ll n,ll mod){
  if(n == 0) return 1;
  ll res = mod_pow(x * x % mod,n / 2,mod);
  if(n & 1) res = res * x % mod;
  return res;
}
void Main() {
  init();
  ll n,m;
  cin >> n >> m;
  ll ans=0;
  REP(i,1,m+1) {
    ans+=nCr(m,i)%MAX*mod_pow(i,n,MAX)%MAX*((m-i)%2?-1:1)+MAX;
    ans%=MAX;
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
0