이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define f first
#define s second
#define oo 1000000001
#define eb emplace_back
#define pb push_back
#define mpr make_pair
#define size(v) (int)v.size()
#define ln '\n'
#define ull unsigned long long
#define ll long long
#define all(v) v.begin(), v.end()
#define iospeed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//#define pbase 361549
//#define imod 1073737591
//#define uimod 2147479307u
//#define llmod 292187309552789533ll
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
void show(vector<T> &v) {
for (T i : v) {
cout << i << ' ';
}
cout << ln;
}
void solve() {
int n;
cin >> n;
vi a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
vvi dp(2, vi(n + 1));
for (int i = 1; i <= n; ++i) {
dp[n & 1][i] = 1;
}
const int mod = 1e6 + 7;
int res = 1;
vi pmax(n + 1);
pmax[1] = a[1];
for (int i = 2; i <= n; ++i) {
pmax[i] = max(pmax[i - 1], a[i]);
}
for (int i = n - 1; i >= 1; --i) {
for (int m = 1; m <= i; ++m) {
dp[i & 1][m] = (1ll * m * dp[(i + 1) & 1][m] + dp[(i + 1) & 1][m + 1]) % mod;
}
res = (1ll * (a[i + 1] - 1) * dp[(i + 1) & 1][pmax[i]] + res) % mod;
}
cout << res << ln;
}
int main() {
iospeed;
solve();
return 0;
}
# | 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... |