답안 #521470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521470 2022-02-02T08:16:03 Z errorgorn Magneti (COCI21_magneti) C++17
110 / 110
218 ms 24672 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define ub upper_bound
#define lb lower_bound

#define rep(x,s,e) for (int x=s;x!=e;x++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(177013);

const int MOD=1000000007;

ll qexp(ll b,ll p,int m){
    ll res=1;
    while (p){
        if (p&1) res=(res*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return res;
}

ll inv(ll i){
	return qexp(i,MOD-2,MOD);
}

ll fix(ll i){
	i%=MOD;
	if (i<0) i+=MOD;
	return i;
}

ll fac[1000005];
ll ifac[1000005];

ll nCk(int i,int j){
	if (i<j) return 0;
	return fac[i]*ifac[j]%MOD*ifac[i-j]%MOD;
}

int n,k;
int arr[55];

ll memo[2][55][10005]; //cc,val

int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	fac[0]=1;
	rep(x,1,1000005) fac[x]=fac[x-1]*x%MOD;
	ifac[1000004]=inv(fac[1000004]);
	for (int x=1000004;x>=1;x--) ifac[x-1]=ifac[x]*x%MOD;
	
	cin>>n>>k;
	rep(x,0,n) cin>>arr[x];
	
	if (n==1){
		cout<<k<<endl;
		return 0;
	}
	if (n==2){
		ll space=k-max(arr[0],arr[1])+1;
		if (space<2) cout<<0<<endl;
		else cout<<space*(space-1)<<endl;
		
		return 0;
	}
	
	sort(arr,arr+n);
	
	int a=0,b=1;
	memo[a][0][0]=1;
	rep(i,0,n){
		memset(memo[b],0,sizeof(memo[b]));
		
		rep(x,0,50) rep(y,0,10005){
			memo[b][x+1][y]=(memo[b][x+1][y]+(x+1)*memo[a][x][y])%MOD;
			if (y+arr[i]<=k)
				memo[b][x][y+arr[i]]=(memo[b][x][y+arr[i]]+memo[a][x][y]*2*x)%MOD;
			if (x>=2 && y+arr[i]*2<=k)
				memo[b][x-1][y+2*arr[i]]=(memo[b][x-1][y+2*arr[i]]+memo[a][x][y]*(x-1))%MOD;
		}
		swap(a,b);
	}
	
	ll ans=0;
	rep(l,0,10005) if (memo[a][1][l]){
		ans=(ans+nCk(k-l+(n-1),n)*memo[a][1][l])%MOD;
		//cout<<l<<" "<<memo[a][1][l]<<endl;
	}
	
	cout<<ans%MOD<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 24648 KB Output is correct
2 Correct 89 ms 24568 KB Output is correct
3 Correct 54 ms 24516 KB Output is correct
4 Correct 36 ms 24524 KB Output is correct
5 Correct 63 ms 24504 KB Output is correct
6 Correct 114 ms 24572 KB Output is correct
7 Correct 97 ms 24580 KB Output is correct
8 Correct 16 ms 15868 KB Output is correct
9 Correct 86 ms 24572 KB Output is correct
10 Correct 16 ms 15888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 24564 KB Output is correct
2 Correct 27 ms 24516 KB Output is correct
3 Correct 53 ms 24568 KB Output is correct
4 Correct 32 ms 24520 KB Output is correct
5 Correct 59 ms 24564 KB Output is correct
6 Correct 33 ms 24556 KB Output is correct
7 Correct 56 ms 24568 KB Output is correct
8 Correct 36 ms 24532 KB Output is correct
9 Correct 28 ms 24556 KB Output is correct
10 Correct 15 ms 15948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 24564 KB Output is correct
2 Correct 49 ms 24568 KB Output is correct
3 Correct 62 ms 24564 KB Output is correct
4 Correct 50 ms 24672 KB Output is correct
5 Correct 66 ms 24564 KB Output is correct
6 Correct 47 ms 24544 KB Output is correct
7 Correct 61 ms 24496 KB Output is correct
8 Correct 34 ms 24472 KB Output is correct
9 Correct 49 ms 24556 KB Output is correct
10 Correct 35 ms 24524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 24648 KB Output is correct
2 Correct 89 ms 24568 KB Output is correct
3 Correct 54 ms 24516 KB Output is correct
4 Correct 36 ms 24524 KB Output is correct
5 Correct 63 ms 24504 KB Output is correct
6 Correct 114 ms 24572 KB Output is correct
7 Correct 97 ms 24580 KB Output is correct
8 Correct 16 ms 15868 KB Output is correct
9 Correct 86 ms 24572 KB Output is correct
10 Correct 16 ms 15888 KB Output is correct
11 Correct 57 ms 24564 KB Output is correct
12 Correct 27 ms 24516 KB Output is correct
13 Correct 53 ms 24568 KB Output is correct
14 Correct 32 ms 24520 KB Output is correct
15 Correct 59 ms 24564 KB Output is correct
16 Correct 33 ms 24556 KB Output is correct
17 Correct 56 ms 24568 KB Output is correct
18 Correct 36 ms 24532 KB Output is correct
19 Correct 28 ms 24556 KB Output is correct
20 Correct 15 ms 15948 KB Output is correct
21 Correct 64 ms 24564 KB Output is correct
22 Correct 49 ms 24568 KB Output is correct
23 Correct 62 ms 24564 KB Output is correct
24 Correct 50 ms 24672 KB Output is correct
25 Correct 66 ms 24564 KB Output is correct
26 Correct 47 ms 24544 KB Output is correct
27 Correct 61 ms 24496 KB Output is correct
28 Correct 34 ms 24472 KB Output is correct
29 Correct 49 ms 24556 KB Output is correct
30 Correct 35 ms 24524 KB Output is correct
31 Correct 207 ms 24568 KB Output is correct
32 Correct 151 ms 24564 KB Output is correct
33 Correct 201 ms 24568 KB Output is correct
34 Correct 107 ms 24664 KB Output is correct
35 Correct 191 ms 24524 KB Output is correct
36 Correct 57 ms 24632 KB Output is correct
37 Correct 200 ms 24576 KB Output is correct
38 Correct 135 ms 24568 KB Output is correct
39 Correct 190 ms 24512 KB Output is correct
40 Correct 110 ms 24564 KB Output is correct
41 Correct 196 ms 24524 KB Output is correct
42 Correct 39 ms 24564 KB Output is correct
43 Correct 195 ms 24568 KB Output is correct
44 Correct 78 ms 24524 KB Output is correct
45 Correct 216 ms 24568 KB Output is correct
46 Correct 18 ms 15944 KB Output is correct
47 Correct 86 ms 24564 KB Output is correct
48 Correct 75 ms 24576 KB Output is correct
49 Correct 35 ms 24552 KB Output is correct
50 Correct 35 ms 24480 KB Output is correct