結果

問題 No.1035 Color Box
ユーザー kilalakilala
提出日時 2020-04-24 22:22:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,778 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 85,428 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 03:33:50
合計ジャッジ時間 2,263 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

int ff[100005];  

int gcd(int a,int b)
{
    if(b==0)
return a;
else
return gcd(b,a%b);
}

int x,y;
void Extended_gcd(int a,int b)
{
    if(b==0)
    {
       x=1;
       y=0;
    }
    else
    {
       Extended_gcd(b,a%b);
       long t=x;
       x=y;
       y=t-(a/b)*y;
    }
}

int C(int a,int b)
{
    if(b>a)
return 0;
    b=(ff[a-b]*ff[b])%M;
    a=ff[a];
    int c=gcd(a,b);
    a/=c;
    b/=c;
    Extended_gcd(b,M);
    x=(x+M)%M;
    x=(x*a)%M;
    return x;
}

int Combination(int n, int m)
{
        int ans=1;
int a,b;
while(m||n)
{
        a=n%M;
b=m%M;
n/=M;
m/=M;
ans=(ans*C(a,b))%M;
}
return ans;
}

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;
    ff[0]=1;
for(int i=1;i<=100004;i++) 
ff[i]=(ff[i-1]*i)%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) * Combination(m, j ) % M;
        ans[n] = (ans[n] + M) % M;
        k *= -1;
    }
    cout << ans[n] << endl;
    return 0;
}
0