結果

問題 No.1035 Color Box
ユーザー 夜
提出日時 2021-07-02 20:05:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 92,372 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2023-09-11 13:12:27
合計ジャッジ時間 2,973 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
8,040 KB
testcase_01 AC 15 ms
8,076 KB
testcase_02 AC 15 ms
8,232 KB
testcase_03 AC 18 ms
8,036 KB
testcase_04 AC 19 ms
8,052 KB
testcase_05 AC 17 ms
8,236 KB
testcase_06 AC 15 ms
8,040 KB
testcase_07 AC 17 ms
8,316 KB
testcase_08 AC 48 ms
8,044 KB
testcase_09 AC 29 ms
8,040 KB
testcase_10 AC 15 ms
8,080 KB
testcase_11 AC 16 ms
8,040 KB
testcase_12 AC 16 ms
8,080 KB
testcase_13 AC 40 ms
8,112 KB
testcase_14 AC 44 ms
8,080 KB
testcase_15 AC 52 ms
8,072 KB
testcase_16 AC 16 ms
8,232 KB
testcase_17 AC 16 ms
8,240 KB
testcase_18 AC 15 ms
8,048 KB
testcase_19 AC 52 ms
8,084 KB
testcase_20 AC 15 ms
8,312 KB
testcase_21 AC 15 ms
8,056 KB
testcase_22 AC 16 ms
8,092 KB
testcase_23 AC 15 ms
8,088 KB
testcase_24 AC 16 ms
8,088 KB
testcase_25 AC 16 ms
8,040 KB
testcase_26 AC 15 ms
8,140 KB
testcase_27 AC 16 ms
8,236 KB
testcase_28 AC 16 ms
8,040 KB
testcase_29 AC 15 ms
8,348 KB
testcase_30 AC 15 ms
8,092 KB
testcase_31 AC 16 ms
8,084 KB
testcase_32 AC 15 ms
8,336 KB
testcase_33 AC 16 ms
8,044 KB
testcase_34 AC 16 ms
8,052 KB
testcase_35 AC 15 ms
8,084 KB
testcase_36 AC 16 ms
8,052 KB
testcase_37 AC 16 ms
8,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long mod = 1000000007;
long long m_pow(long long x, long long y) {
	long long ans = 1;
	while (y > 0) {
		if ((y & 1) == 1) {
			ans = ans * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}
long long fac[200020], finv[200020], inv[200020];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; 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(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main() {
	COMinit();
	long long n, m;
	cin >> n >> m;
	long long ans = 0;
	for (int i = m; i > 0; i--) {
		if ((m - i) % 2 == 0) {
			ans += m_pow(i, n) * COM(m, i) % mod;
		}
		else {
			ans -= m_pow(i, n) * COM(m, i) % mod;
		}
		ans %= mod;
	}
	cout << (ans + mod) % mod << endl;
}
0