結果

問題 No.1035 Color Box
ユーザー kilalakilala
提出日時 2020-04-24 22:08:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,091 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 84,684 KB
実行使用メモリ 18,880 KB
最終ジャッジ日時 2024-04-23 03:24:41
合計ジャッジ時間 7,266 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
vector<ll> ans(100005, 1); long long M = 1e9 + 7;
map<pair<ll, ll>, ll> cmb;

long long qpow(long long a, long long n) {
    long long ret = 1;
    a = (a % M + M) % M;
    for (; n; n >>= 1) {
        if (n & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}


ll comp(ll a,ll b,ll p)//composite num C(a,b)%p
{
    if (cmb.count(make_pair(a,b))) return cmb[make_pair(a, b)];
    if (cmb.count(make_pair(a,a-b))) return cmb[make_pair(a, a-b)];
	if(a<b)return 0;
	if(a==b)return 1;
	if(b>a-b)b=a-b;
	int ans=1,ca=1,cb=1;
	for(ll i=0;i<b;i++)
	{
		ca=(ca*(a-i))%p;
		cb=(cb*(b-i))%p;
	}
	ans=(ca*qpow(cb,p-2))%p;
	cmb[make_pair(a, b)] = ans;
    return ans;
}

int main()
{
    int n, m;
    cin >> n >> m;
    ans[1] = m;
    ans[n] = qpow(m, n);
    int k = -1;
    for (int j = 1; j < m; ++j) {
        ans[n] += k * qpow(j, n) * comp(m, j, M) % M;
        ans[n] = (ans[n] + M) % M;
        k *= -1;
    }
    cout << ans[n] << endl;
    return 0;
}
0