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;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i = a; i < b; i++)
const ll MOD = 1000007;
const int MAXN = 10000;
int main() {
int n; cin >> n;
vi state(n);
rep(i,0,n) cin >> state[i];
int MAX = 1, LEFT = n;
vector<pii> add(n);
rep(i,0,n) {
add[LEFT - 1] = {state[i] - 1, MAX};
MAX = max(MAX, state[i]);
LEFT--;
}
ll ans = 1;
vector<vector<ll>> dp(2, vector<ll>(MAXN + 5, 1));
rep(i,0,MAXN+1) dp[1][i] = i+1;
ans = (ans + dp[0][ add[0].second ] * add[0].first) % MOD;
ans = (ans + dp[1][ add[1].second ] * add[1].first) % MOD;
rep(x,2,MAXN+1) {
rep(y,0,MAXN+1) {
dp[x&1][y] = (y * dp[(x - 1)&1][y] + dp[(x - 1)&1][y + 1]) % MOD;
}
if (x < n) ans = (ans + dp[x&1][ add[x].second ] * add[x].first) % MOD;
}
cout << ans << endl;
}
# | 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... |