Submission #26835

# Submission time Handle Problem Language Result Execution time Memory
26835 2017-07-06T08:32:08 Z Andrei1998 Calvinball championship (CEOI15_teams) C++14
100 / 100
123 ms 2184 KB
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000 + 7;
const int NMAX = 10000 + 5;

int N;
int v[NMAX];
int dp[2][NMAX];

bool freq[NMAX];
int col[NMAX];

int main()
{
    cin >> N;
    for (int i = 1; i <= N; ++ i)
        cin >> v[i];

    col[0] = 0;
    for (int i = 1; i <= N; ++ i) {
        col[i] = col[i - 1];
        if (!freq[v[i]]) {
            freq[v[i]] = true;
            ++ col[i];
        }
    }

    int ans = 1;
    for (int i = N; i; -- i) {
        if (i == N) {
            for (int col = 1; col <= N; ++ col)
                dp[N & 1][col] = 1;
        }
        else {
            for (int col = 0; col <= i; ++ col)
                dp[i & 1][col] = (dp[(i + 1) & 1][col + 1] + 1LL * col * dp[(i + 1) & 1][col]) % MOD;
        }
        ans = (ans + dp[i & 1][col[i - 1]] * (v[i] - 1LL)) % MOD;
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2184 KB Output is correct
2 Correct 0 ms 2184 KB Output is correct
3 Correct 0 ms 2184 KB Output is correct
4 Correct 0 ms 2184 KB Output is correct
5 Correct 0 ms 2184 KB Output is correct
6 Correct 0 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2184 KB Output is correct
2 Correct 0 ms 2184 KB Output is correct
3 Correct 0 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2184 KB Output is correct
2 Correct 0 ms 2184 KB Output is correct
3 Correct 0 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2184 KB Output is correct
2 Correct 0 ms 2184 KB Output is correct
3 Correct 0 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2184 KB Output is correct
2 Correct 0 ms 2184 KB Output is correct
3 Correct 0 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2184 KB Output is correct
2 Correct 0 ms 2184 KB Output is correct
3 Correct 3 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2184 KB Output is correct
2 Correct 26 ms 2184 KB Output is correct
3 Correct 29 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 2184 KB Output is correct
2 Correct 119 ms 2184 KB Output is correct
3 Correct 116 ms 2184 KB Output is correct