/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
#define int long long
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0 //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt" : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg) ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg arg,Args... args){put (arg)<<" ";print(args...);}
void debug(){eol;} template<typename Arg,typename... Args> void debug(Arg arg,Args... args){put (arg)<<" ";debug(args...);}
int getInt(){int a; get a; return a;}
//code goes here
const int mod = 1e6 + 7;
void run() {
int n;
get n;
int ans = 1;
int lim = 0;
int a[n];
rep(i, 0, n)
a[i] = getInt() - 1;
int dp[n];
rep(i, 0, n)
dp[i] = 0;
rep(i, 1, n) {
int nxt[n];
rep(j, 0, n) {
nxt[j] = (dp[j] * (j + 1)) % mod;
if (j) {
nxt[j] = (nxt[j] + dp[j - 1]) % mod;
swap(dp[j - 1], nxt[j - 1]);
}
}
dp[lim] = (dp[lim] + a[i]) % mod;
lim = max(a[i], lim);
}
rep(j, 0, n)
ans = (ans + dp[j]) % mod;
put ans;
}
int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); return 0;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
464 KB |
Output is correct |
3 |
Correct |
4 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
752 KB |
Output is correct |
6 |
Correct |
3 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
752 KB |
Output is correct |
2 |
Correct |
2 ms |
752 KB |
Output is correct |
3 |
Correct |
4 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
816 KB |
Output is correct |
2 |
Correct |
3 ms |
816 KB |
Output is correct |
3 |
Correct |
2 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
816 KB |
Output is correct |
2 |
Correct |
3 ms |
816 KB |
Output is correct |
3 |
Correct |
2 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
816 KB |
Output is correct |
2 |
Correct |
6 ms |
816 KB |
Output is correct |
3 |
Correct |
4 ms |
916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
916 KB |
Output is correct |
2 |
Correct |
10 ms |
916 KB |
Output is correct |
3 |
Correct |
12 ms |
916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
615 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
1100 KB |
Output is correct |
2 |
Correct |
183 ms |
1100 KB |
Output is correct |
3 |
Correct |
150 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
714 ms |
1228 KB |
Output is correct |
2 |
Correct |
690 ms |
1264 KB |
Output is correct |
3 |
Correct |
726 ms |
1300 KB |
Output is correct |