답안 #704013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704013 2023-03-01T11:19:55 Z Pacybwoah Magneti (COCI21_magneti) C++14
10 / 110
1000 ms 468 KB
#include<iostream>
#include<vector>
#include<utility>
#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<pair<ll,ll>> vec(n);
    vector<ll> fac(20001);
    fac[0]=1;
    for(ll i=1;i<=20000;i++) fac[i]=fac[i-1]*i%mod;
    for(int i=0;i<n;i++) cin>>vec[i].first;
    bool flag=1;
    for(int i=0;i<n-1;i++){
        if(vec[i].first!=vec[i+1].first){
            flag=0;
            break;
        }
    }
    if(flag){
        ll r=vec[0].first;
        ll k=(l-1-(n-1)*r);
        if(k<0){
            cout<<0;
            return 0;
        }
        cout<<fac[k+n]*inverse(fac[n])%mod*inverse(fac[k])%mod*fac[n]%mod;
        return 0;
    }
    if(n<=10){
        ll ans=0;
        for(int i=0;i<n;i++) vec[i].second=i;
        sort(vec.begin(),vec.end());
        do{
            ll k=l-1;
            for(int i=0;i<n-1;i++) k-=max(vec[i].first,vec[i+1].first);
            if(k<0) continue;
            ans=(ans+fac[k+n]*inverse(fac[n])%mod*inverse(fac[k])%mod)%mod;
        }while(next_permutation(vec.begin(),vec.end()));
        cout<<ans;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Execution timed out 1088 ms 468 KB Time limit exceeded
12 Halted 0 ms 0 KB -