結果

問題 No.1035 Color Box
ユーザー dekomori_sanaedekomori_sanae
提出日時 2020-04-24 21:38:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,118 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 85,556 KB
実行使用メモリ 8,312 KB
最終ジャッジ日時 2023-08-05 04:39:04
合計ジャッジ時間 5,459 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
7,988 KB
testcase_01 AC 81 ms
8,036 KB
testcase_02 AC 80 ms
8,056 KB
testcase_03 AC 82 ms
8,040 KB
testcase_04 AC 82 ms
8,040 KB
testcase_05 AC 80 ms
8,020 KB
testcase_06 AC 81 ms
8,096 KB
testcase_07 AC 80 ms
8,052 KB
testcase_08 AC 93 ms
8,120 KB
testcase_09 AC 86 ms
8,188 KB
testcase_10 AC 80 ms
8,072 KB
testcase_11 AC 80 ms
8,060 KB
testcase_12 AC 79 ms
8,252 KB
testcase_13 AC 93 ms
7,992 KB
testcase_14 AC 96 ms
8,024 KB
testcase_15 AC 97 ms
8,076 KB
testcase_16 AC 79 ms
7,996 KB
testcase_17 AC 80 ms
8,040 KB
testcase_18 AC 80 ms
8,132 KB
testcase_19 AC 95 ms
8,104 KB
testcase_20 AC 80 ms
8,192 KB
testcase_21 AC 80 ms
8,072 KB
testcase_22 AC 81 ms
8,120 KB
testcase_23 AC 80 ms
8,084 KB
testcase_24 AC 80 ms
8,056 KB
testcase_25 AC 81 ms
8,096 KB
testcase_26 AC 80 ms
8,124 KB
testcase_27 AC 80 ms
8,060 KB
testcase_28 AC 80 ms
7,996 KB
testcase_29 AC 80 ms
8,028 KB
testcase_30 AC 80 ms
7,988 KB
testcase_31 AC 80 ms
8,076 KB
testcase_32 AC 80 ms
7,988 KB
testcase_33 AC 81 ms
8,312 KB
testcase_34 AC 80 ms
8,056 KB
testcase_35 AC 80 ms
7,988 KB
testcase_36 AC 80 ms
7,992 KB
testcase_37 AC 81 ms
8,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 200010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n, m;
    cin >> n >> m;

    init();

    ll x = 0;
    ll y = 0;
    ll cnt = 0;
    for(ll i = m; i >= 1; i--) {
        ll a = Comb(m, i);
        ll b = modpow(i, n);
        if(cnt%2 == 0) {
            x += (a*b)%mod;
            x %= mod;
        }
        else {
            y += (a*b)%mod;
            y %= mod;
        }
        cnt++;
    }

    ll ans = (x + mod - y)%mod;
    
    out(ans);
    re0;
}
0