Submission #3419882


Source Code Expand

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}

int main()
{
	int n; ll d;
	cin>>n>>d;
	ll f[901];
	f[0]=1;
	for(ll i=1; i<=900; i++){
		f[i]=f[i-1]*i%MOD;
	}
	ll invf[901];
	invf[900]=inv(f[900]);
	for(ll i=899; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;

	int a[31];
	int asum=0;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		asum+=(a[i]-1);
	}
	ll dp[31][31][901]={};
	dp[0][0][0]=1;
	for(int i=1; i<=n; i++){
		for(int j=0; j<=i; j++){
			for(int k=0; k<=asum; k++){
				dp[i][j][k]=dp[i-1][j][k];
				for(int l=0; l<a[i]; l++){
					if(k>=l) dp[i][j][k]+=(dp[i-1][j-1][k-l]*f[k]%MOD*invf[k-l]%MOD*invf[l]%MOD);
				}
				dp[i][j][k]%=MOD;
			}
		}
	}
	ll fd[901];
	fd[0]=1, fd[1]=d;
	ll prod=d;
	for(ll i=2; i<=asum; i++){
		prod=prod*(d-i+1)%MOD;
		fd[i]=prod*invf[i]%MOD;
	}
	ll ans=powmod((ll)n, d);
	for(int i=1; i<=n; i++){
		for(int j=0; j<=asum; j++){
			if(d<j) continue;
			if(i%2){
				ans-=(fd[j]*dp[n][i][j]%MOD*powmod((ll)(n-i), d-(ll)j)%MOD);
				ans+=MOD;
			}else{
				ans+=(fd[j]*dp[n][i][j]%MOD*powmod((ll)(n-i), d-(ll)j)%MOD);
			}
			ans%=MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Submission Info

Submission Time
Task D - 天下一ボディービルコンテスト
User chocorusk
Language C++14 (GCC 5.4.1)
Score 280
Code Size 1762 Byte
Status AC
Exec Time 95 ms
Memory 7168 KB

Judge Result

Set Name level1 level2 level3
Score / Max Score 40 / 40 100 / 100 140 / 140
Status
AC × 27
AC × 50
AC × 74
Set Name Test Cases
level1 level1_max_0.txt, level1_maxrand_0.txt, level1_maxrand_1.txt, level1_maxrand_2.txt, level1_maxrand_3.txt, level1_maxrand_4.txt, level1_maxrand_5.txt, level1_maxrand_6.txt, level1_maxrand_7.txt, level1_maxrand_8.txt, level1_maxrand_9.txt, level1_min1_0.txt, level1_min2_0.txt, level1_min3_0.txt, level1_min4_0.txt, level1_rand_0.txt, level1_rand_1.txt, level1_rand_2.txt, level1_rand_3.txt, level1_rand_4.txt, level1_rand_5.txt, level1_rand_6.txt, level1_rand_7.txt, level1_rand_8.txt, level1_rand_9.txt, level1_sample1.txt, level1_sample2.txt
level2 level1_max_0.txt, level1_maxrand_0.txt, level1_maxrand_1.txt, level1_maxrand_2.txt, level1_maxrand_3.txt, level1_maxrand_4.txt, level1_maxrand_5.txt, level1_maxrand_6.txt, level1_maxrand_7.txt, level1_maxrand_8.txt, level1_maxrand_9.txt, level1_min1_0.txt, level1_min2_0.txt, level1_min3_0.txt, level1_min4_0.txt, level1_rand_0.txt, level1_rand_1.txt, level1_rand_2.txt, level1_rand_3.txt, level1_rand_4.txt, level1_rand_5.txt, level1_rand_6.txt, level1_rand_7.txt, level1_rand_8.txt, level1_rand_9.txt, level1_sample1.txt, level1_sample2.txt, level2_max_0.txt, level2_maxrand_0.txt, level2_maxrand_1.txt, level2_maxrand_2.txt, level2_maxrand_3.txt, level2_maxrand_4.txt, level2_maxrand_5.txt, level2_maxrand_6.txt, level2_maxrand_7.txt, level2_maxrand_8.txt, level2_maxrand_9.txt, level2_min1_0.txt, level2_min2_0.txt, level2_rand_0.txt, level2_rand_1.txt, level2_rand_2.txt, level2_rand_3.txt, level2_rand_4.txt, level2_rand_5.txt, level2_rand_6.txt, level2_rand_7.txt, level2_rand_8.txt, level2_rand_9.txt
level3 level1_max_0.txt, level1_maxrand_0.txt, level1_maxrand_1.txt, level1_maxrand_2.txt, level1_maxrand_3.txt, level1_maxrand_4.txt, level1_maxrand_5.txt, level1_maxrand_6.txt, level1_maxrand_7.txt, level1_maxrand_8.txt, level1_maxrand_9.txt, level1_min1_0.txt, level1_min2_0.txt, level1_min3_0.txt, level1_min4_0.txt, level1_rand_0.txt, level1_rand_1.txt, level1_rand_2.txt, level1_rand_3.txt, level1_rand_4.txt, level1_rand_5.txt, level1_rand_6.txt, level1_rand_7.txt, level1_rand_8.txt, level1_rand_9.txt, level1_sample1.txt, level1_sample2.txt, level2_max_0.txt, level2_maxrand_0.txt, level2_maxrand_1.txt, level2_maxrand_2.txt, level2_maxrand_3.txt, level2_maxrand_4.txt, level2_maxrand_5.txt, level2_maxrand_6.txt, level2_maxrand_7.txt, level2_maxrand_8.txt, level2_maxrand_9.txt, level2_min1_0.txt, level2_min2_0.txt, level2_rand_0.txt, level2_rand_1.txt, level2_rand_2.txt, level2_rand_3.txt, level2_rand_4.txt, level2_rand_5.txt, level2_rand_6.txt, level2_rand_7.txt, level2_rand_8.txt, level2_rand_9.txt, level3_max_0.txt, level3_maxrand_0.txt, level3_maxrand_1.txt, level3_maxrand_2.txt, level3_maxrand_3.txt, level3_maxrand_4.txt, level3_maxrand_5.txt, level3_maxrand_6.txt, level3_maxrand_7.txt, level3_maxrand_8.txt, level3_maxrand_9.txt, level3_min1_0.txt, level3_min2_0.txt, level3_rand_0.txt, level3_rand_1.txt, level3_rand_2.txt, level3_rand_3.txt, level3_rand_4.txt, level3_rand_5.txt, level3_rand_6.txt, level3_rand_7.txt, level3_rand_8.txt, level3_rand_9.txt, level3_sample3.txt
Case Name Status Exec Time Memory
level1_max_0.txt AC 3 ms 7040 KB
level1_maxrand_0.txt AC 3 ms 7040 KB
level1_maxrand_1.txt AC 2 ms 7040 KB
level1_maxrand_2.txt AC 3 ms 7040 KB
level1_maxrand_3.txt AC 3 ms 7040 KB
level1_maxrand_4.txt AC 3 ms 7040 KB
level1_maxrand_5.txt AC 3 ms 7040 KB
level1_maxrand_6.txt AC 3 ms 7040 KB
level1_maxrand_7.txt AC 3 ms 7040 KB
level1_maxrand_8.txt AC 3 ms 7040 KB
level1_maxrand_9.txt AC 3 ms 7040 KB
level1_min1_0.txt AC 3 ms 7040 KB
level1_min2_0.txt AC 3 ms 7040 KB
level1_min3_0.txt AC 3 ms 7040 KB
level1_min4_0.txt AC 3 ms 7040 KB
level1_rand_0.txt AC 3 ms 7040 KB
level1_rand_1.txt AC 3 ms 7040 KB
level1_rand_2.txt AC 3 ms 7040 KB
level1_rand_3.txt AC 3 ms 7040 KB
level1_rand_4.txt AC 3 ms 7040 KB
level1_rand_5.txt AC 3 ms 7040 KB
level1_rand_6.txt AC 3 ms 7040 KB
level1_rand_7.txt AC 3 ms 7040 KB
level1_rand_8.txt AC 3 ms 7040 KB
level1_rand_9.txt AC 3 ms 7040 KB
level1_sample1.txt AC 3 ms 7040 KB
level1_sample2.txt AC 3 ms 7040 KB
level2_max_0.txt AC 3 ms 7040 KB
level2_maxrand_0.txt AC 3 ms 7040 KB
level2_maxrand_1.txt AC 3 ms 7040 KB
level2_maxrand_2.txt AC 3 ms 7040 KB
level2_maxrand_3.txt AC 3 ms 7040 KB
level2_maxrand_4.txt AC 3 ms 7040 KB
level2_maxrand_5.txt AC 3 ms 7040 KB
level2_maxrand_6.txt AC 3 ms 7040 KB
level2_maxrand_7.txt AC 3 ms 7040 KB
level2_maxrand_8.txt AC 3 ms 7040 KB
level2_maxrand_9.txt AC 3 ms 7040 KB
level2_min1_0.txt AC 3 ms 7040 KB
level2_min2_0.txt AC 3 ms 7040 KB
level2_rand_0.txt AC 3 ms 7040 KB
level2_rand_1.txt AC 3 ms 7040 KB
level2_rand_2.txt AC 2 ms 7040 KB
level2_rand_3.txt AC 3 ms 7040 KB
level2_rand_4.txt AC 3 ms 7040 KB
level2_rand_5.txt AC 3 ms 7040 KB
level2_rand_6.txt AC 3 ms 7040 KB
level2_rand_7.txt AC 3 ms 7040 KB
level2_rand_8.txt AC 3 ms 7040 KB
level2_rand_9.txt AC 3 ms 7040 KB
level3_max_0.txt AC 95 ms 7040 KB
level3_maxrand_0.txt AC 28 ms 7040 KB
level3_maxrand_1.txt AC 21 ms 7040 KB
level3_maxrand_2.txt AC 22 ms 7040 KB
level3_maxrand_3.txt AC 25 ms 7040 KB
level3_maxrand_4.txt AC 23 ms 7040 KB
level3_maxrand_5.txt AC 31 ms 7040 KB
level3_maxrand_6.txt AC 29 ms 7040 KB
level3_maxrand_7.txt AC 23 ms 7040 KB
level3_maxrand_8.txt AC 29 ms 7040 KB
level3_maxrand_9.txt AC 22 ms 7040 KB
level3_min1_0.txt AC 3 ms 7040 KB
level3_min2_0.txt AC 3 ms 7040 KB
level3_rand_0.txt AC 14 ms 7040 KB
level3_rand_1.txt AC 11 ms 7040 KB
level3_rand_2.txt AC 3 ms 7040 KB
level3_rand_3.txt AC 5 ms 7040 KB
level3_rand_4.txt AC 2 ms 7040 KB
level3_rand_5.txt AC 6 ms 7040 KB
level3_rand_6.txt AC 5 ms 7040 KB
level3_rand_7.txt AC 9 ms 7040 KB
level3_rand_8.txt AC 3 ms 7040 KB
level3_rand_9.txt AC 5 ms 7168 KB
level3_sample3.txt AC 4 ms 7040 KB