結果

問題 No.391 CODING WAR
ユーザー glretoglreto
提出日時 2020-09-26 19:11:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,846 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 92,040 KB
実行使用メモリ 15,620 KB
最終ジャッジ日時 2023-09-12 00:37:57
合計ジャッジ時間 2,649 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
15,284 KB
testcase_01 AC 14 ms
15,344 KB
testcase_02 AC 13 ms
15,368 KB
testcase_03 AC 14 ms
15,352 KB
testcase_04 AC 13 ms
15,268 KB
testcase_05 AC 14 ms
15,340 KB
testcase_06 AC 14 ms
15,488 KB
testcase_07 AC 14 ms
15,308 KB
testcase_08 AC 14 ms
15,308 KB
testcase_09 AC 32 ms
15,296 KB
testcase_10 AC 31 ms
15,264 KB
testcase_11 AC 21 ms
15,308 KB
testcase_12 AC 13 ms
15,500 KB
testcase_13 AC 28 ms
15,300 KB
testcase_14 AC 26 ms
15,364 KB
testcase_15 AC 27 ms
15,368 KB
testcase_16 AC 21 ms
15,268 KB
testcase_17 AC 23 ms
15,620 KB
testcase_18 AC 20 ms
15,348 KB
testcase_19 AC 21 ms
15,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int inf = 1 << 31 - 1;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
//fac : 階乗 finv
// テーブルを作る前処理
void COMint() {
    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;
}
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }return res;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(void) {
    ll n, k,sum = 0; cin >> n >> k;COMint();
    rep(i, k+1) {
        sum += MOD;
        if ((k - i) % 2 == 0) sum += COM(k, i) * mod_pow(i, n, MOD);
        else sum -= (COM(k, i) * mod_pow(i, n, MOD)) % MOD;
        sum %= MOD;
    }cout << sum << endl;
}
0