답안 #704072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704072 2023-03-01T13:49:50 Z Pacybwoah Magneti (COCI21_magneti) C++14
110 / 110
201 ms 208456 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll power(ll a,ll b){
    if(b==0) return 1;
    if(b&1) return power(a,b-1)*a%mod;
    ll tmp=power(a,b/2);
    return tmp*tmp%mod;
}
ll inverse(ll a){
    return power(a,mod-2);
}
int main(){
    ll n,l;
    cin>>n>>l;
    vector<ll> vec(n);
    vector<ll> fac(20001);
    fac[0]=1;
    for(ll i=1;i<=20000;i++) fac[i]=fac[i-1]*i%mod;
    vector<ll> invfac(20001);
    for(ll i=0;i<=20000;i++) invfac[i]=inverse(fac[i]);
    for(int i=0;i<n;i++) cin>>vec[i];
    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(l+1,0)));
    dp[1][1][0]=1;
    sort(vec.begin(),vec.end());
    for(ll i=2;i<=n;i++){
        for(ll j=1;j<=i;j++){
            for(ll k=0;k<=l;k++){
                if(j+1<=n&&k-2*vec[i-1]>=0) dp[i][j][k]=dp[i-1][j+1][k-2*vec[i-1]]*(j*(j+1)%mod)%mod;
                if(j-1>=0) dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-1][k])%mod;
                if(k-vec[i-1]>=0) dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k-vec[i-1]]*j*2%mod)%mod;
            }
        }
    }
    ll ans=0;
    for(int i=0;i<l;i++){
        ans=(ans+fac[l-1-i+n]*invfac[n]%mod*invfac[l-1-i]%mod*dp[n][1][i]%mod)%mod;
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 208392 KB Output is correct
2 Correct 6 ms 1748 KB Output is correct
3 Correct 16 ms 10708 KB Output is correct
4 Correct 8 ms 2900 KB Output is correct
5 Correct 15 ms 12344 KB Output is correct
6 Correct 57 ms 62628 KB Output is correct
7 Correct 67 ms 103968 KB Output is correct
8 Correct 6 ms 724 KB Output is correct
9 Correct 34 ms 50408 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 10964 KB Output is correct
2 Correct 6 ms 1452 KB Output is correct
3 Correct 14 ms 11012 KB Output is correct
4 Correct 8 ms 2420 KB Output is correct
5 Correct 15 ms 10964 KB Output is correct
6 Correct 7 ms 2516 KB Output is correct
7 Correct 13 ms 10964 KB Output is correct
8 Correct 6 ms 1492 KB Output is correct
9 Correct 6 ms 2348 KB Output is correct
10 Correct 6 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2900 KB Output is correct
2 Correct 6 ms 1364 KB Output is correct
3 Correct 7 ms 2900 KB Output is correct
4 Correct 7 ms 1876 KB Output is correct
5 Correct 9 ms 2900 KB Output is correct
6 Correct 5 ms 680 KB Output is correct
7 Correct 7 ms 2900 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 6 ms 1620 KB Output is correct
10 Correct 6 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 208392 KB Output is correct
2 Correct 6 ms 1748 KB Output is correct
3 Correct 16 ms 10708 KB Output is correct
4 Correct 8 ms 2900 KB Output is correct
5 Correct 15 ms 12344 KB Output is correct
6 Correct 57 ms 62628 KB Output is correct
7 Correct 67 ms 103968 KB Output is correct
8 Correct 6 ms 724 KB Output is correct
9 Correct 34 ms 50408 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 16 ms 10964 KB Output is correct
12 Correct 6 ms 1452 KB Output is correct
13 Correct 14 ms 11012 KB Output is correct
14 Correct 8 ms 2420 KB Output is correct
15 Correct 15 ms 10964 KB Output is correct
16 Correct 7 ms 2516 KB Output is correct
17 Correct 13 ms 10964 KB Output is correct
18 Correct 6 ms 1492 KB Output is correct
19 Correct 6 ms 2348 KB Output is correct
20 Correct 6 ms 852 KB Output is correct
21 Correct 7 ms 2900 KB Output is correct
22 Correct 6 ms 1364 KB Output is correct
23 Correct 7 ms 2900 KB Output is correct
24 Correct 7 ms 1876 KB Output is correct
25 Correct 9 ms 2900 KB Output is correct
26 Correct 5 ms 680 KB Output is correct
27 Correct 7 ms 2900 KB Output is correct
28 Correct 5 ms 852 KB Output is correct
29 Correct 6 ms 1620 KB Output is correct
30 Correct 6 ms 852 KB Output is correct
31 Correct 186 ms 208392 KB Output is correct
32 Correct 121 ms 127452 KB Output is correct
33 Correct 192 ms 208456 KB Output is correct
34 Correct 51 ms 44200 KB Output is correct
35 Correct 195 ms 208424 KB Output is correct
36 Correct 16 ms 13652 KB Output is correct
37 Correct 201 ms 208424 KB Output is correct
38 Correct 34 ms 33528 KB Output is correct
39 Correct 181 ms 208420 KB Output is correct
40 Correct 57 ms 63700 KB Output is correct
41 Correct 187 ms 208372 KB Output is correct
42 Correct 6 ms 2172 KB Output is correct
43 Correct 185 ms 208296 KB Output is correct
44 Correct 22 ms 22228 KB Output is correct
45 Correct 187 ms 208392 KB Output is correct
46 Correct 5 ms 1492 KB Output is correct
47 Correct 44 ms 63160 KB Output is correct
48 Correct 23 ms 28244 KB Output is correct
49 Correct 8 ms 5332 KB Output is correct
50 Correct 5 ms 980 KB Output is correct