結果

問題 No.1035 Color Box
ユーザー wunderkammer2wunderkammer2
提出日時 2020-07-01 10:01:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,955 bytes
コンパイル時間 880 ms
コンパイル使用メモリ 103,856 KB
実行使用メモリ 15,060 KB
最終ジャッジ日時 2023-10-11 22:01:26
合計ジャッジ時間 3,298 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
14,728 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 22 ms
14,840 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 42 ms
14,780 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 20 ms
14,732 KB
testcase_12 WA -
testcase_13 AC 39 ms
15,040 KB
testcase_14 AC 41 ms
14,784 KB
testcase_15 AC 45 ms
14,924 KB
testcase_16 AC 20 ms
14,980 KB
testcase_17 AC 21 ms
14,724 KB
testcase_18 AC 20 ms
14,972 KB
testcase_19 AC 44 ms
14,776 KB
testcase_20 AC 21 ms
14,724 KB
testcase_21 AC 21 ms
14,872 KB
testcase_22 AC 20 ms
14,712 KB
testcase_23 AC 21 ms
14,996 KB
testcase_24 AC 20 ms
14,768 KB
testcase_25 AC 21 ms
14,716 KB
testcase_26 AC 20 ms
14,772 KB
testcase_27 AC 21 ms
14,716 KB
testcase_28 AC 21 ms
14,936 KB
testcase_29 AC 21 ms
14,728 KB
testcase_30 AC 21 ms
14,836 KB
testcase_31 AC 21 ms
14,984 KB
testcase_32 AC 20 ms
14,980 KB
testcase_33 AC 20 ms
15,056 KB
testcase_34 AC 20 ms
14,908 KB
testcase_35 AC 20 ms
14,824 KB
testcase_36 AC 20 ms
14,980 KB
testcase_37 AC 21 ms
15,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }




const int MAX = 510000;

vector<ll> 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;
        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;
}


ll pmod(ll n, ll p) {
    ll m = n % MOD;
    if (p == 0) return 1;
    ll rtn = pmod((m * m) % MOD, p / 2) % MOD;
    if (p % 2 == 1) rtn = rtn * m % MOD;
    return rtn;
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    COMinit();

    ll ans = 0;

    reple(i, 0, M - 1)
    {
        //包除原理の符号
        int s = i % 2 == 0 ? 1 : -1;

        ans += s * COM(M, M - i) * pmod(M - i, N);

        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}
0