# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110618 | someone_aa | Calvinball championship (CEOI15_teams) | C++17 | 226 ms | 528 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>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 11000;
const ll mod = 1000007;
int dp[2][maxn];
int a[maxn], n;
int prefmax[maxn];
int main() {
// dp[i][j] -> If we are given a sequence of arbitrary length and maximum element j,
// on how many ways can we extend it if we can add exactly i elements
cin>>n;
prefmax[0] = 1;
for(int i=1;i<=n;i++) {
cin>>a[i];
prefmax[i] = max(prefmax[i-1], a[i]);
}
for(int i=1;i<=n;i++) {
dp[0][i] = 1;
}
int result = 0;
int maxv = 1;
for(int i=n;i>=1;i--) {
for(int j=1;j<=n;j++) {
int d = n - i + 1;
dp[d%2][j] = j*dp[(d-1)%2][j] + dp[(d-1)%2][j+1];
dp[d%2][j] %= mod;
}
result += (a[i]-1)*(dp[(n-i)%2][prefmax[i-1]]);
result %= mod;
}
cout<<(result+1)%mod;
return 0;
}
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... |