답안 #851894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851894 2023-09-20T18:47:57 Z vjudge1 Magneti (COCI21_magneti) C++17
10 / 110
1000 ms 744 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 1000000
#define till 1000001
// # of primes till 1e6 = 7e4
using namespace std;
using pii = array<int,2>;
const int mod=1000000007ll;

void mul(int*a,int b){
    *a=((*a%mod)*(b%mod));
}
int mul(int a,int b){
    return ((a%mod)*(b%mod))%mod;
}

int expo(int a,int b){
    int ans=1;
    while(b){
        if(b&1){
            mul(&ans,a);
        }
        mul(&a,a);
        b>>=1;
    }
    return ans;
}
int fact[20001];
int divy[20001];
int comb(int a,int b){
    return mul(mul(fact[a],divy[b]),divy[a-b]);
}

void solve(){
    int n,l;
    cin>>n>>l;
    fact[0]=1;
    divy[0]=1;
    for(int i=1;i<20001;i++){
        fact[i]=mul(fact[i-1],i);
        divy[i]=expo(fact[i],mod-2);
    }
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    if(a[0]==a[n-1]){
        if(a[0]*(n-1)+1>l){
            cout<<"0\n";
            return;
        }
        cout<<mul(fact[n],comb(l-a[0]*(n-1)-1+n,n));
    }else{
        pii b[n];
        for(int i=0;i<n;i++){
            b[i]={a[i],i};        
        }
        sort(b,b+n);
        int ans=0;
        do{
            int sums=l-1;
            for(int i=0;i<n-1;i++){
                sums-=max(b[i][0],b[i+1][0]);
            }
            /*
            for(pii k:b){
                cerr<<k[0]<<" ";
            }cerr<<"\n";
            cerr<<sums<<"\n";
            */
            if(0<=sums)ans+=comb(sums+n,n);
        }while(next_permutation(b,b+n));
        cout<<ans<<"\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen("in","r",stdin);
    freopen("out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 612 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 121 ms 744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1048 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 612 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 660 KB Output is correct
11 Incorrect 121 ms 744 KB Output isn't correct
12 Halted 0 ms 0 KB -