Submission #746325

# Submission time Handle Problem Language Result Execution time Memory
746325 2023-05-22T10:58:45 Z Trunkty Magneti (COCI21_magneti) C++14
0 / 110
11 ms 4180 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,l,ans,mod=1e9+7;
int arr[55];
int dp[55][10005];
int comb[10005]; // comb[i] = l choose i 

int dopow(int x, int y){
    if(y==0){
        return 1;
    }
    int z = dopow(x,y/2);
    if(y%2){
        return (((z*z)%mod)*x)%mod;
    }
    else{
        return (z*z)%mod;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> l;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
    }
    sort(arr+1,arr+n+1);
    dp[1][1] = 1;
    for(int i=2;i<=n;i++){
        for(int j=0;j<=l;j++){
            if(j>=arr[i]){
                dp[i][j] += dp[i-1][j-arr[i]]*2LL;
                dp[i][j] %= mod;
            }
            if(j>=arr[i]*2LL-1LL){
                dp[i][j] += dp[i-1][j-arr[i]*2LL+1LL]*(i-2LL);
                dp[i][j] %= mod;
            }
        }
    }
    comb[0] = 1;
    for(int j=1;j<=l;j++){
        comb[j] = comb[j-1]*(l-j+1LL);
        comb[j] %= mod;
        comb[j] *= dopow(j,mod-2LL);
        comb[j] %= mod;
    }
    for(int j=0;j<=l;j++){
        ans += dp[n][j]*comb[j];
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4180 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 5 ms 980 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4180 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 5 ms 980 KB Output isn't correct
4 Halted 0 ms 0 KB -