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;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int mod = 1e9 + 7;
void nxt(vector<int> &v) {
int n = (int) v.size();
vector<int> prefmax(n);
prefmax[0] = 1;
for(int i = 1; i < n; i++) {
prefmax[i] = max(prefmax[i - 1], v[i]);
}
if(prefmax[n - 1] == n) {
// 1 2 3 ... n
return;
}
for(int i = n - 1; i >= 0; i--) {
if(prefmax[i - 1] >= v[i]) {
v[i]++;
return;
}
v[i] = 1;
}
}
void solve() {
int n;
cin >> n;
vector<int> v(n, 1);
vector<int> goal(n);
for(int i = 0; i < n; i++) {
cin >> goal[i];
}
int ans = 0;
ans++;
while(v != goal) {
nxt(v);
ans++;
}
ans %= mod;
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# | 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... |