結果

問題 No.1035 Color Box
ユーザー hamrayhamray
提出日時 2020-06-28 19:24:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 2,630 bytes
コンパイル時間 1,209 ms
コンパイル使用メモリ 145,612 KB
実行使用メモリ 50,508 KB
最終ジャッジ日時 2023-09-22 08:54:38
合計ジャッジ時間 5,880 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
50,232 KB
testcase_01 AC 61 ms
50,232 KB
testcase_02 AC 53 ms
50,360 KB
testcase_03 AC 61 ms
50,300 KB
testcase_04 AC 63 ms
50,284 KB
testcase_05 AC 52 ms
50,360 KB
testcase_06 AC 50 ms
50,252 KB
testcase_07 AC 67 ms
50,232 KB
testcase_08 AC 62 ms
50,232 KB
testcase_09 AC 66 ms
50,232 KB
testcase_10 AC 58 ms
50,296 KB
testcase_11 AC 55 ms
50,508 KB
testcase_12 AC 70 ms
50,232 KB
testcase_13 AC 69 ms
50,244 KB
testcase_14 AC 66 ms
50,228 KB
testcase_15 AC 66 ms
50,232 KB
testcase_16 AC 77 ms
50,428 KB
testcase_17 AC 59 ms
50,344 KB
testcase_18 AC 54 ms
50,508 KB
testcase_19 AC 67 ms
50,232 KB
testcase_20 AC 56 ms
50,364 KB
testcase_21 AC 56 ms
50,288 KB
testcase_22 AC 56 ms
50,252 KB
testcase_23 AC 60 ms
50,432 KB
testcase_24 AC 60 ms
50,252 KB
testcase_25 AC 67 ms
50,228 KB
testcase_26 AC 61 ms
50,280 KB
testcase_27 AC 60 ms
50,432 KB
testcase_28 AC 64 ms
50,220 KB
testcase_29 AC 66 ms
50,232 KB
testcase_30 AC 63 ms
50,272 KB
testcase_31 AC 56 ms
50,244 KB
testcase_32 AC 54 ms
50,284 KB
testcase_33 AC 60 ms
50,224 KB
testcase_34 AC 54 ms
50,256 KB
testcase_35 AC 55 ms
50,308 KB
testcase_36 AC 62 ms
50,288 KB
testcase_37 AC 66 ms
50,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集
const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
ll modPow(ll x, ll n, ll mod = MOD){
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;
 
        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N, M; cin >> N >> M;
  COMinit();

  ll ans = 0;
  for(int i=0; i<=M; i++){
    ll tmp = COM(M, i) * modPow(M-i, N, MOD);
    
    if(i%2 == 1) tmp *= -1;
    ans += tmp;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}
0