結果

問題 No.1035 Color Box
ユーザー misora192misora192
提出日時 2020-06-05 09:05:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 1,418 ms
コンパイル使用メモリ 164,372 KB
実行使用メモリ 5,272 KB
最終ジャッジ日時 2023-08-21 09:13:51
合計ジャッジ時間 4,419 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
4,948 KB
testcase_01 AC 4 ms
4,960 KB
testcase_02 AC 4 ms
5,008 KB
testcase_03 AC 12 ms
5,080 KB
testcase_04 AC 13 ms
5,076 KB
testcase_05 AC 6 ms
5,032 KB
testcase_06 AC 5 ms
5,064 KB
testcase_07 AC 4 ms
5,004 KB
testcase_08 AC 99 ms
5,016 KB
testcase_09 AC 42 ms
4,964 KB
testcase_10 AC 3 ms
5,008 KB
testcase_11 AC 4 ms
5,016 KB
testcase_12 AC 3 ms
4,968 KB
testcase_13 AC 78 ms
5,064 KB
testcase_14 AC 88 ms
5,152 KB
testcase_15 AC 111 ms
5,272 KB
testcase_16 AC 4 ms
4,968 KB
testcase_17 AC 4 ms
5,004 KB
testcase_18 AC 3 ms
4,960 KB
testcase_19 AC 112 ms
4,972 KB
testcase_20 AC 4 ms
5,000 KB
testcase_21 AC 4 ms
5,080 KB
testcase_22 AC 4 ms
4,964 KB
testcase_23 AC 4 ms
4,964 KB
testcase_24 AC 4 ms
4,956 KB
testcase_25 AC 4 ms
4,956 KB
testcase_26 AC 3 ms
5,072 KB
testcase_27 AC 4 ms
4,964 KB
testcase_28 AC 4 ms
4,948 KB
testcase_29 AC 3 ms
5,144 KB
testcase_30 AC 4 ms
5,144 KB
testcase_31 AC 4 ms
4,952 KB
testcase_32 AC 4 ms
4,964 KB
testcase_33 AC 3 ms
4,964 KB
testcase_34 AC 4 ms
5,004 KB
testcase_35 AC 4 ms
5,000 KB
testcase_36 AC 4 ms
5,132 KB
testcase_37 AC 4 ms
4,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const ll max_n = 202020;
ll fact[max_n];
bool fact_init = false;

ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2 == 1) return a * pow(a, b - 1) % MOD;

	ll d = pow(a, b / 2) % MOD;
	return d * d % MOD;
}

ll comb(ll n, ll k){
	if(!fact_init){
		fact[0] = 1;
		fact[1] = 1;

		for(ll i = 2; i < max_n; i++){
			fact[i] = fact[i-1] * i;
			fact[i] %= MOD;
		}

		fact_init = true;
	}

	ll ret = fact[n];
	ret *= pow(fact[k],MOD-2);
	ret %= MOD;
	ret *= pow(fact[n-k],MOD-2);
	ret %= MOD;
	return ret;

	// X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}

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

	ll n, m;
	cin >> n >> m;

	ll ans = 0;
	ll t = 1;
	rep(i, m+1){
		ans += MOD + t * comb(m, i) * pow(m - i, n) % MOD;
		ans %= MOD;
		t *= -1;
	}

	cout << ans << endl;
}
0