結果

問題 No.1035 Color Box
ユーザー onakaT_TitaionakaT_Titai
提出日時 2019-02-27 05:47:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,737 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 94,140 KB
実行使用メモリ 19,292 KB
最終ジャッジ日時 2023-09-05 09:09:30
合計ジャッジ時間 2,691 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
18,988 KB
testcase_01 AC 16 ms
19,020 KB
testcase_02 AC 16 ms
18,968 KB
testcase_03 AC 16 ms
19,104 KB
testcase_04 AC 16 ms
19,036 KB
testcase_05 AC 16 ms
19,036 KB
testcase_06 AC 15 ms
18,984 KB
testcase_07 AC 16 ms
19,044 KB
testcase_08 AC 23 ms
18,984 KB
testcase_09 AC 18 ms
19,164 KB
testcase_10 AC 16 ms
19,292 KB
testcase_11 AC 15 ms
19,032 KB
testcase_12 AC 15 ms
18,984 KB
testcase_13 AC 22 ms
18,960 KB
testcase_14 AC 23 ms
18,984 KB
testcase_15 AC 24 ms
19,004 KB
testcase_16 AC 15 ms
18,984 KB
testcase_17 AC 15 ms
19,036 KB
testcase_18 AC 15 ms
18,968 KB
testcase_19 AC 25 ms
18,984 KB
testcase_20 AC 15 ms
19,028 KB
testcase_21 AC 16 ms
18,984 KB
testcase_22 AC 16 ms
19,024 KB
testcase_23 AC 15 ms
19,028 KB
testcase_24 AC 17 ms
18,988 KB
testcase_25 AC 16 ms
18,980 KB
testcase_26 AC 16 ms
19,236 KB
testcase_27 AC 15 ms
19,020 KB
testcase_28 AC 15 ms
18,964 KB
testcase_29 AC 15 ms
18,980 KB
testcase_30 AC 15 ms
19,032 KB
testcase_31 AC 15 ms
18,992 KB
testcase_32 AC 15 ms
19,036 KB
testcase_33 AC 15 ms
19,236 KB
testcase_34 AC 16 ms
18,988 KB
testcase_35 AC 16 ms
18,972 KB
testcase_36 AC 15 ms
19,104 KB
testcase_37 AC 16 ms
18,972 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