Submission #3466103


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

#define MOD 1000000007

ll mi[35];
ll modpow(ll a, ll b){
	ll r = 1;
	while(b){
		if(b&1)r=r*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return r;
}

int n,d;
int a[35];

ll dp[35][925];

int main(){
	mi[0] = mi[1] = 1;
	FOR(x,2,35)mi[x] = MOD - (MOD/x)*mi[MOD%x]%MOD;

	scanf("%d%d",&n,&d);
	REP(i,n)scanf("%d",a+i);

	dp[0][0] = 1ll;

	REP(i,n){
		FORR(sz,0,n)REP(used,901){
			ll comb = 1;
			FOR(x,0,a[i]){
				if(used+x>d)break;
				(dp[sz+1][used+x] += dp[sz][used] * comb % MOD) %= MOD;
				comb = comb * (d-used-x) % MOD * mi[x+1] % MOD;
			}
		}
	}
	// ll ans = modpow(n,d);
	ll ans = 0;
	REP(sz,n+1)REP(used,min(901,d+1)){
		// printf("%lld%c",dp[sz][used],used==d?'\n':' ');
		ans += MOD - (sz%2==1 ? 1 : -1) * dp[sz][used] % MOD * modpow(n-sz, d-used) % MOD;
		ans %= MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&d);
                     ^
./Main.cpp:42:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  REP(i,n)scanf("%d",a+i);
                         ^

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 2 ms 256 KB
level1_maxrand_0.txt AC 2 ms 256 KB
level1_maxrand_1.txt AC 1 ms 256 KB
level1_maxrand_2.txt AC 2 ms 256 KB
level1_maxrand_3.txt AC 2 ms 256 KB
level1_maxrand_4.txt AC 2 ms 256 KB
level1_maxrand_5.txt AC 1 ms 256 KB
level1_maxrand_6.txt AC 2 ms 256 KB
level1_maxrand_7.txt AC 2 ms 256 KB
level1_maxrand_8.txt AC 2 ms 256 KB
level1_maxrand_9.txt AC 2 ms 256 KB
level1_min1_0.txt AC 1 ms 256 KB
level1_min2_0.txt AC 1 ms 256 KB
level1_min3_0.txt AC 1 ms 256 KB
level1_min4_0.txt AC 1 ms 256 KB
level1_rand_0.txt AC 1 ms 256 KB
level1_rand_1.txt AC 1 ms 256 KB
level1_rand_2.txt AC 1 ms 256 KB
level1_rand_3.txt AC 1 ms 256 KB
level1_rand_4.txt AC 1 ms 256 KB
level1_rand_5.txt AC 1 ms 256 KB
level1_rand_6.txt AC 1 ms 256 KB
level1_rand_7.txt AC 1 ms 256 KB
level1_rand_8.txt AC 1 ms 256 KB
level1_rand_9.txt AC 1 ms 256 KB
level1_sample1.txt AC 1 ms 256 KB
level1_sample2.txt AC 1 ms 256 KB
level2_max_0.txt AC 3 ms 256 KB
level2_maxrand_0.txt AC 3 ms 256 KB
level2_maxrand_1.txt AC 3 ms 256 KB
level2_maxrand_2.txt AC 2 ms 256 KB
level2_maxrand_3.txt AC 3 ms 256 KB
level2_maxrand_4.txt AC 3 ms 256 KB
level2_maxrand_5.txt AC 3 ms 256 KB
level2_maxrand_6.txt AC 3 ms 256 KB
level2_maxrand_7.txt AC 3 ms 256 KB
level2_maxrand_8.txt AC 3 ms 256 KB
level2_maxrand_9.txt AC 3 ms 256 KB
level2_min1_0.txt AC 2 ms 256 KB
level2_min2_0.txt AC 1 ms 256 KB
level2_rand_0.txt AC 2 ms 256 KB
level2_rand_1.txt AC 1 ms 256 KB
level2_rand_2.txt AC 1 ms 256 KB
level2_rand_3.txt AC 2 ms 256 KB
level2_rand_4.txt AC 3 ms 256 KB
level2_rand_5.txt AC 2 ms 256 KB
level2_rand_6.txt AC 3 ms 256 KB
level2_rand_7.txt AC 1 ms 256 KB
level2_rand_8.txt AC 2 ms 256 KB
level2_rand_9.txt AC 2 ms 256 KB
level3_max_0.txt AC 252 ms 512 KB
level3_maxrand_0.txt AC 135 ms 512 KB
level3_maxrand_1.txt AC 117 ms 512 KB
level3_maxrand_2.txt AC 117 ms 512 KB
level3_maxrand_3.txt AC 126 ms 512 KB
level3_maxrand_4.txt AC 117 ms 512 KB
level3_maxrand_5.txt AC 140 ms 512 KB
level3_maxrand_6.txt AC 140 ms 512 KB
level3_maxrand_7.txt AC 120 ms 512 KB
level3_maxrand_8.txt AC 131 ms 512 KB
level3_maxrand_9.txt AC 113 ms 512 KB
level3_min1_0.txt AC 12 ms 512 KB
level3_min2_0.txt AC 2 ms 256 KB
level3_rand_0.txt AC 80 ms 384 KB
level3_rand_1.txt AC 63 ms 384 KB
level3_rand_2.txt AC 2 ms 256 KB
level3_rand_3.txt AC 29 ms 384 KB
level3_rand_4.txt AC 3 ms 256 KB
level3_rand_5.txt AC 30 ms 384 KB
level3_rand_6.txt AC 26 ms 384 KB
level3_rand_7.txt AC 50 ms 384 KB
level3_rand_8.txt AC 13 ms 384 KB
level3_rand_9.txt AC 7 ms 256 KB
level3_sample3.txt AC 13 ms 384 KB