結果

問題 No.1035 Color Box
ユーザー ningenMeningenMe
提出日時 2020-04-23 22:55:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,737 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 97,768 KB
実行使用メモリ 19,252 KB
最終ジャッジ日時 2024-04-22 03:15:30
合計ジャッジ時間 2,272 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
19,192 KB
testcase_01 AC 15 ms
19,184 KB
testcase_02 AC 16 ms
19,216 KB
testcase_03 AC 15 ms
19,216 KB
testcase_04 AC 14 ms
19,088 KB
testcase_05 AC 15 ms
19,172 KB
testcase_06 AC 15 ms
19,108 KB
testcase_07 AC 16 ms
19,188 KB
testcase_08 AC 21 ms
19,040 KB
testcase_09 AC 17 ms
19,244 KB
testcase_10 AC 14 ms
19,056 KB
testcase_11 AC 14 ms
19,196 KB
testcase_12 AC 14 ms
19,240 KB
testcase_13 AC 18 ms
19,096 KB
testcase_14 AC 20 ms
19,052 KB
testcase_15 AC 21 ms
19,132 KB
testcase_16 AC 15 ms
19,252 KB
testcase_17 AC 15 ms
19,104 KB
testcase_18 AC 14 ms
19,112 KB
testcase_19 AC 21 ms
19,068 KB
testcase_20 AC 15 ms
19,128 KB
testcase_21 AC 16 ms
19,064 KB
testcase_22 AC 16 ms
19,164 KB
testcase_23 AC 15 ms
19,124 KB
testcase_24 AC 14 ms
19,152 KB
testcase_25 AC 14 ms
19,080 KB
testcase_26 AC 15 ms
19,164 KB
testcase_27 AC 15 ms
19,084 KB
testcase_28 AC 14 ms
19,176 KB
testcase_29 AC 15 ms
19,072 KB
testcase_30 AC 14 ms
19,064 KB
testcase_31 AC 15 ms
19,184 KB
testcase_32 AC 14 ms
19,052 KB
testcase_33 AC 14 ms
19,112 KB
testcase_34 AC 16 ms
19,248 KB
testcase_35 AC 15 ms
19,176 KB
testcase_36 AC 15 ms
19,092 KB
testcase_37 AC 14 ms
19,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

const int MAXN = 1000000;
Int fact[MAXN], inv[MAXN];

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

void init_fact() {
    fact[0] = 1;
    for(int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for(int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

Int comb(int n, int r) {
    if(r < 0 || n < r) return 0;
    return fact[n] * inv[n-r] % MOD * inv[r] % MOD;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}


int main(){
    cin.tie(0);

    int N, M; cin >> N >> M;
    Int ans = 0;
    init_fact();
    for (int i = 1; i <= M; i++){
        if ((M-i)%2){
            ans += -1LL*(comb(M, i)*mod_pow(i, N))%MOD;
        }else{
            ans += (comb(M, i)*mod_pow(i, N))%MOD;
        }
        ans += MOD;
        ans %= MOD;
    }
    cout << ans << endl;


}
0