結果

問題 No.391 CODING WAR
ユーザー motmot
提出日時 2020-06-28 03:22:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 1,847 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 81,560 KB
実行使用メモリ 6,496 KB
最終ジャッジ日時 2023-09-20 17:51:42
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,360 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 257 ms
6,420 KB
testcase_10 AC 146 ms
6,496 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 181 ms
6,448 KB
testcase_14 AC 192 ms
5,840 KB
testcase_15 AC 235 ms
6,204 KB
testcase_16 AC 129 ms
5,140 KB
testcase_17 AC 159 ms
5,320 KB
testcase_18 AC 104 ms
4,564 KB
testcase_19 AC 107 ms
4,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll N, M;
ll comb[100005];
ll P1[100005];
ll P2[100005];
ll frac[100005];

void prepare(){
  P1[M] = 1;
  P1[M-1] = 1;
  for(ll i=M-2;i>0;--i){
    P1[i] = P1[i+1]*(M-i);
    P1[i] %= mod;
  }
  P2[0] = 1;
  P2[1] = 1;
  for(ll i=2;i<=M;++i){
    P2[i] = P2[i-1]*i;
    P2[i] %= mod;
  }
  ll shita1, shita2, tmpshita1, tmpshita2, h, two;
  comb[0] = 1;
  for(int k=1;k<=M;++k){
    h = mod - 2;
    shita1 = 1;
    shita2 = 1;
    while(h>0){
      two = 1;
      tmpshita1 = P1[k];
      tmpshita2 = P2[k];
      while(2*two<=h){
        two *= 2;
        tmpshita1 *= tmpshita1;
        tmpshita1 %= mod;
        tmpshita2 *= tmpshita2;
        tmpshita2 %= mod;
      }
      h -= two;
      shita1 *= tmpshita1;
      shita1 %= mod;
      shita2 *= tmpshita2;
      shita2 %= mod;
    }
    comb[k] = P2[M]*shita1%mod*shita2%mod;
  }
  ll tmp;
  for(ll k=0;k<=M;++k){
    h = N;
    frac[k] = 1;
    while(h>0){
      two = 1;
      tmp = k;
      while(2*two<=h){
        two *= 2;
        tmp *= tmp;
        tmp %= mod;
      }
      h -= two;
      frac[k] *= tmp;
      frac[k] %= mod;
    }
  }
}

int main() {
  cin>>N>>M;
  if(N<M) {
    cout<<0<<endl;
    return 0;
  }
  prepare();
  ll ans = 0;
  for(int k=0;k<=M;++k){
    if(k%2==0){
      ans += comb[k]*frac[M-k]%mod;
    }
    else{
      ans -= comb[k]*frac[M-k]%mod;
    }
    ans = (ans + mod)%mod;
  }
  cout<<ans<<endl;
}

0