# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90754 | Vinhspm | Calvinball championship (CEOI15_teams) | C++14 | 398 ms | 1044 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
const int N = 1e4 + 5;
const int mod = 1e6 + 7;
int n, num;
int a[N], cnt[N];
int f[2][N];
void add(int &x, int y) { x = (x + y) % mod; }
signed main()
{
scanf("%d", &n);
FOR(i, 1, n) {
scanf("%d", &a[i]), cnt[ a[i] ] ++;
if(cnt[ a[i] ] == 1) num ++;
}
int sum = 1, las = 0, nex = 1;
FOR(i, 0, n) f[las][i] = 1;
for(int i = n; i >= 1; --i) {
FOR(j, 0, i) {
add(f[nex][j], f[las][j] * j);
add(f[nex][j], f[las][j + 1]);
}
cnt[ a[i] ] --; if(cnt[ a[i] ] == 0) num --;
FOR(t, 1, a[i] - 1) {
cnt[t] ++; if(cnt[t] == 1) num ++;
add(sum, f[las][num]);
cnt[t] --; if(cnt[t] == 0) num --;
}
swap(nex, las);
FOR(j, 0, i) f[nex][j] = 0;
}
printf("%d", sum);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |