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 all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int maxn = 1e4+1, mod = 1e6 + 7;
using state = array<int, maxn>;
int n;
state def;
void add(int &a, int b) { a = a+b>=mod?a+b-mod:a+b; }
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
def.fill(0);
state dp = def;
int lk = 0;
for(int A, i = 1; i <= n; i++) {
cin >> A;
auto ndp = def;
add(ndp[lk], A-1);
lk = max(lk, A);
for(int k = 0; k < i; k++) {
ndp[k] = (ndp[k] + dp[k]*1ll*k)%mod;
add(ndp[k+1], dp[k]);
}
dp = ndp;
//for(int i = 0; i <= n; i++) cout << dp[i] << " "; cout << endl;
}
int sm = 1;
for(int i = 0; i <= n; i++) add(sm, dp[i]);
cout << sm << '\n';
}
# | 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... |