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;
const int k_N = 1e4 + 3;
const int k_Mod = 1e9 + 7;
int n, a[k_N];
pair<int, bool> dp[k_N][k_N][2];
int solve(int pos, int cnt, bool equal){
if(pos == n) return 1;
auto &[ans, solved] = dp[pos][cnt][equal];
if(solved) return ans;
solved = true;
ans = 0;
if(!equal){
ans = ((long long)solve(pos + 1, cnt, false) * cnt + solve(pos + 1, cnt + 1, false)) % k_Mod;
return ans;
}
ans = ((long long)solve(pos + 1, cnt, false) * min(cnt, a[pos] - 1)) % k_Mod;
if(a[pos] <= cnt)
ans += solve(pos + 1, cnt, true);
else if(a[pos] == cnt + 1)
ans += solve(pos + 1, cnt + 1, true);
else if(a[pos] > cnt + 1)
ans += solve(pos + 1, cnt + 1, false);
ans %= k_Mod;
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; ++i)
cin >> a[i];
cout << solve(0, 0, true) << "\n";
}
Compilation message (stderr)
teams.cpp: In function 'int solve(int, int, bool)':
teams.cpp:14:11: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto &[ans, solved] = dp[pos][cnt][equal];
^
# | 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... |