제출 #753005

#제출 시각아이디문제언어결과실행 시간메모리
753005Ronin13Calvinball championship (CEOI15_teams)C++14
10 / 100
1068 ms916 KiB
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
#define pii pair<int,int>
using namespace std;
const int nmax = 10001;
ll mod = 1e6 + 7;

ll dp[2][nmax];
ll DP[nmax];
ll f[nmax];
ll inv[nmax];
ll c[nmax];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    //fil(2);
    int a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    dp[0][0] = 1;
    DP[0] = 1;
    c[0] = 1;
    for(int i = 1; i <= n ;i++){
        for(int j = 1; j <= i ;j++){
            dp[1][j] = dp[0][j - 1] + dp[0][j] * (ll)j;
            dp[1][j] %= mod;
        }
        for(int j = 0; j <= n; j++){
            dp[0][j] = dp[1][j];
            DP[i] += dp[0][j];
            DP[i] %= mod;
            dp[1][j] = 0;
        }
       // cout << DP[i] << ' ';
    }
    set <int> st;
    ll po[n + 1];
    ll ans = 1;
    for(int i = 1 ;i <= n; ++i){
        c[i] = 1;
        for(int j = i - 1; j >= 2 ;j--)
            c[j] += c[j - 1], c[j] %= mod;
        if(i != 1){
            po[0] = 1;
            ll k= st.size();
            for(int j = 1; j <= n; j++)
                po[j] = po[j - 1] * k % mod;
            ll res = 0;
            for(int x = 0; x <= n - i; x++){
                res += c[x] * DP[x] * po[n - i - x];
                res %= mod;
            }
            res *= (ll)(a[i] - 1);
            res %= mod;
            ans += res;
            ans %= mod;
        }
        st.insert(a[i]);
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...