結果

問題 No.1035 Color Box
ユーザー eQeeQe
提出日時 2020-04-28 22:32:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 144,548 KB
実行使用メモリ 6,572 KB
最終ジャッジ日時 2023-08-16 20:38:00
合計ジャッジ時間 4,006 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
6,480 KB
testcase_01 AC 15 ms
4,924 KB
testcase_02 AC 15 ms
4,920 KB
testcase_03 AC 16 ms
5,104 KB
testcase_04 AC 16 ms
5,372 KB
testcase_05 AC 16 ms
5,096 KB
testcase_06 AC 15 ms
5,148 KB
testcase_07 AC 16 ms
4,940 KB
testcase_08 AC 24 ms
6,572 KB
testcase_09 AC 20 ms
5,540 KB
testcase_10 AC 16 ms
4,944 KB
testcase_11 AC 16 ms
4,936 KB
testcase_12 AC 16 ms
5,224 KB
testcase_13 AC 22 ms
6,048 KB
testcase_14 AC 22 ms
6,128 KB
testcase_15 AC 26 ms
6,496 KB
testcase_16 AC 15 ms
5,252 KB
testcase_17 AC 15 ms
4,920 KB
testcase_18 AC 16 ms
4,940 KB
testcase_19 AC 23 ms
6,548 KB
testcase_20 AC 15 ms
4,928 KB
testcase_21 AC 15 ms
5,004 KB
testcase_22 AC 16 ms
4,944 KB
testcase_23 AC 15 ms
5,048 KB
testcase_24 AC 15 ms
4,932 KB
testcase_25 AC 16 ms
5,008 KB
testcase_26 AC 15 ms
4,980 KB
testcase_27 AC 15 ms
4,924 KB
testcase_28 AC 15 ms
5,244 KB
testcase_29 AC 15 ms
4,968 KB
testcase_30 AC 15 ms
4,980 KB
testcase_31 AC 15 ms
5,000 KB
testcase_32 AC 16 ms
4,944 KB
testcase_33 AC 16 ms
4,984 KB
testcase_34 AC 15 ms
4,984 KB
testcase_35 AC 15 ms
5,212 KB
testcase_36 AC 15 ms
4,936 KB
testcase_37 AC 16 ms
4,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/
 
ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

ll fa[MAX], rf[MAX];

ll C(ll n, ll k) {
  if(n<k||n<0||k<0) return 0;
  if(k==0) return 1;
  if(n==k) return 1;
  return fa[n]*rf[k]%MOD*rf[n-k]%MOD;
}

ll N, M;
ll f(ll i) {
  if(i==0) return 0;
  return (C(M, i)*moP(i, N)%MOD-f(i-1)%MOD+MOD)%MOD;
}

int main(void) {
  ll i, j, k;
  
  cin >> N >> M;
  
  fa[0]=rf[0]=1;
  for(i=1; i<MAX; i++) {
    fa[i]=fa[i-1]*i%MOD;
    rf[i]=moP(fa[i], MOD-2);
  }
  
  pt(f(M));
  
}
 
 
0