이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 10010;
const ll MOD = 1000007LL;
ll dp[2][MAXN];
ll tot;
int N,vetor[MAXN];
ll solve(int pos,int maior){
if(dp[pos][maior] != -1) return dp[pos][maior];
if(pos == N + 1){
return dp[pos][maior] = 1;
}
ll ans = 1LL*(maior - 1)*solve(pos+1,maior);
ans += solve(pos+1,maior+1);
return dp[pos][maior] = (int)(ans % MOD);
}
int main(){
cin >> N;
for(int i = 1;i<=N;i++) cin >> vetor[i];
for(int i = 1;i<=N+2;i++) dp[0][i] = 1;
for(int i = N;i>=1;i--){
int maior = 0;
for(int j = 1;j<i;j++) maior = max(maior,vetor[j]);
swap(dp[0],dp[1]);
for(int j = 1;j<=N+1;j++){
dp[0][j] = (j-1)*dp[1][j] + dp[1][j+1];
dp[0][j] %= MOD;
}
for(int j = 1;j<vetor[i];j++){
tot += dp[1][max(j,maior) + 1];
}
tot %= MOD;
}
tot++;
tot %= MOD;
cout << tot << endl;
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... |