結果

問題 No.1035 Color Box
ユーザー recososorecososo
提出日時 2020-04-24 22:51:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 167,992 KB
実行使用メモリ 8,708 KB
最終ジャッジ日時 2023-08-05 05:33:04
合計ジャッジ時間 3,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,464 KB
testcase_01 AC 6 ms
8,316 KB
testcase_02 AC 5 ms
8,096 KB
testcase_03 AC 5 ms
8,196 KB
testcase_04 AC 7 ms
8,240 KB
testcase_05 AC 6 ms
8,064 KB
testcase_06 AC 6 ms
8,056 KB
testcase_07 AC 7 ms
8,584 KB
testcase_08 AC 12 ms
8,504 KB
testcase_09 AC 9 ms
8,456 KB
testcase_10 AC 6 ms
8,096 KB
testcase_11 AC 6 ms
8,132 KB
testcase_12 AC 6 ms
8,172 KB
testcase_13 AC 12 ms
8,508 KB
testcase_14 AC 13 ms
8,708 KB
testcase_15 AC 13 ms
8,508 KB
testcase_16 AC 6 ms
8,168 KB
testcase_17 AC 5 ms
8,252 KB
testcase_18 AC 6 ms
8,184 KB
testcase_19 AC 13 ms
8,516 KB
testcase_20 AC 6 ms
8,052 KB
testcase_21 AC 5 ms
8,048 KB
testcase_22 AC 5 ms
8,092 KB
testcase_23 AC 5 ms
8,052 KB
testcase_24 AC 6 ms
8,044 KB
testcase_25 AC 5 ms
8,060 KB
testcase_26 AC 5 ms
8,048 KB
testcase_27 AC 5 ms
8,060 KB
testcase_28 AC 5 ms
8,120 KB
testcase_29 AC 6 ms
8,092 KB
testcase_30 AC 6 ms
8,040 KB
testcase_31 AC 6 ms
8,156 KB
testcase_32 AC 5 ms
8,048 KB
testcase_33 AC 6 ms
8,232 KB
testcase_34 AC 6 ms
8,064 KB
testcase_35 AC 6 ms
8,052 KB
testcase_36 AC 6 ms
8,156 KB
testcase_37 AC 6 ms
8,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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;
const int mod=1e9+7;
const int MOD=998244353;
const int nmax=200005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin >> n >> m;
    if(m>n){
        cout << 0 << endl;
    }
    vector<ll> t(n+1);
    t[0]=1;
    for(int i=1;i<=n;i++){
        (t[i]=t[i-1]*n)%=mod;
    }
    COMinit();
    ll ans=0;
    for(ll i=m;i>=1;i--){
        ll tmp=pow_mod(i,n,mod)*com(m,i)%mod;
        if((m-i)%2==0){
            (ans+=tmp)%=mod;
        }
        else{
            (ans+=-tmp+mod)%=mod;
        }
    }
    cout << ans << endl;
}
0