답안 #753009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753009 2023-06-04T12:45:21 Z Ronin13 Calvinball championship (CEOI15_teams) C++14
70 / 100
1000 ms 960 KB
#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;

int dp[2][nmax];
int DP[nmax];

int 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] = (ll)dp[0][j - 1] + (ll)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;
    int val[n + 1];
    val[1] = 1;
    st.insert(a[1]);
    for(int i = 2; i <= n; i++){
        st.insert(a[i]);
        val[i] = st.size();
    }
    for(int i = n ;i >= 2; --i){
        c[n - i] = 1;
        for(int j = n - i - 1; j >= 1 ;j--)
            c[j] += c[j - 1], c[j] %= mod;
        if(i != 1){
            po[0] = 1;
            ll k= val[i - 1];
            for(int j = 1; j <= n - i; j++)
                po[j] = po[j - 1] * k % mod;
            ll res = 0;
            for(int x = 0; x <= n - i; x++){
                res += (ll)c[x] * (ll)DP[x] * (ll)po[n - i - x];
                res %= mod;
            }
            res *= (ll)(a[i] - 1);
            res %= mod;
            ans += res;
            ans %= mod;
        }

    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 5 ms 340 KB Output is correct
3 Correct 5 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 360 KB Output is correct
2 Correct 18 ms 360 KB Output is correct
3 Correct 19 ms 412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 497 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 592 KB Time limit exceeded
2 Halted 0 ms 0 KB -