結果

問題 No.1035 Color Box
ユーザー recososorecososo
提出日時 2020-04-24 22:51:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 167,652 KB
実行使用メモリ 8,812 KB
最終ジャッジ日時 2024-04-23 03:46:20
合計ジャッジ時間 2,697 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
8,560 KB
testcase_01 AC 5 ms
8,108 KB
testcase_02 AC 5 ms
8,284 KB
testcase_03 AC 6 ms
8,096 KB
testcase_04 AC 6 ms
8,516 KB
testcase_05 AC 6 ms
8,420 KB
testcase_06 AC 5 ms
8,160 KB
testcase_07 AC 7 ms
8,688 KB
testcase_08 AC 13 ms
8,556 KB
testcase_09 AC 7 ms
8,812 KB
testcase_10 AC 5 ms
8,364 KB
testcase_11 AC 6 ms
8,316 KB
testcase_12 AC 6 ms
8,088 KB
testcase_13 AC 10 ms
8,552 KB
testcase_14 AC 12 ms
8,812 KB
testcase_15 AC 13 ms
8,680 KB
testcase_16 AC 5 ms
8,280 KB
testcase_17 AC 6 ms
8,284 KB
testcase_18 AC 5 ms
8,028 KB
testcase_19 AC 13 ms
8,684 KB
testcase_20 AC 5 ms
8,028 KB
testcase_21 AC 4 ms
8,152 KB
testcase_22 AC 6 ms
8,036 KB
testcase_23 AC 6 ms
8,160 KB
testcase_24 AC 6 ms
8,284 KB
testcase_25 AC 6 ms
8,284 KB
testcase_26 AC 6 ms
8,284 KB
testcase_27 AC 6 ms
8,036 KB
testcase_28 AC 6 ms
8,152 KB
testcase_29 AC 6 ms
8,160 KB
testcase_30 AC 4 ms
8,152 KB
testcase_31 AC 5 ms
8,284 KB
testcase_32 AC 5 ms
8,032 KB
testcase_33 AC 6 ms
8,156 KB
testcase_34 AC 6 ms
8,164 KB
testcase_35 AC 5 ms
8,032 KB
testcase_36 AC 5 ms
8,152 KB
testcase_37 AC 5 ms
8,156 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