# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67898 | polyfish | Calvinball championship (CEOI15_teams) | C++14 | 8 ms | 776 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.
//I love armpit fetish
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"
const int MAX_N = 10002;
const int MOD = 1000007;
int n, a[MAX_N], max_a[MAX_N], f[2][MAX_N];
void enter() {
cin >> n;
for (int i=1; i<=n; ++i)
cin >> a[i];
}
void solve() {
int res = 1, cur = 0;
for (int last=1; last<=n; ++last)
f[cur][last] = 1;
for (int i=1; i<=n; ++i)
max_a[i] = max(max_a[i-1], a[i]);
for (int i=n; i>=1; --i) {
cur ^= 1;
for (int nGroup=1; nGroup<i; ++nGroup) {
f[cur][nGroup] = (f[cur^1][nGroup+1] + 1LL * f[cur^1][nGroup] * nGroup % MOD) % MOD;
}
for (int j=1; j<a[i]; ++j)
res = (res + f[cur^1][max(max_a[i-1], j)]) % MOD;
}
cout << res;
}
int main() {
#define OFFLINE_JUDGE doraemon
#ifdef OFFLINE_JUDGE
freopen(FILE_NAME".inp", "r", stdin);
freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
enter();
solve();
}
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... |