#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly
/*
TASK: hidden
LANG: C++11
*/
using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 10013
#define INF 1000000000000000000LL
#define mp make_pair
#define add push_back
#define remove pop
#define MOD 1000007LL
ll n;
ll values[MAXN];
ll num[MAXN];
ll dp[2][MAXN]; //dp[i][j]: num ways from point i IF the highest number that appears before us is j (implying value of i is at most j + 1)
//dp[i][j] = dp[i + 1][j] * j + dp[i + 1][j + 1]
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> values[i];
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < MAXN; j++) {
dp[i][j] = 1;
}
}
int answer = 0;
ll highestNum = 0;
for (int i = 0; i < n; i++) {
num[i] = highestNum;
highestNum = max(highestNum, values[i]);
}
int old = 0;
for (int i = n - 1; i >= 0; i--) {
answer += ((values[i] - 1) * dp[old][num[i]]) % MOD;
answer %= MOD;
for (int j = 0; j < i; j++) {
dp[1 - old][j] = dp[old][j] * j + dp[old][j + 1];
dp[1 - old][j] %= MOD;
}
old = 1 - old;
}
cout << answer + 1 << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2488 KB |
Output is correct |
2 |
Correct |
0 ms |
2488 KB |
Output is correct |
3 |
Correct |
0 ms |
2488 KB |
Output is correct |
4 |
Correct |
0 ms |
2488 KB |
Output is correct |
5 |
Correct |
0 ms |
2488 KB |
Output is correct |
6 |
Correct |
0 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2488 KB |
Output is correct |
2 |
Correct |
0 ms |
2488 KB |
Output is correct |
3 |
Correct |
0 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2488 KB |
Output is correct |
2 |
Correct |
0 ms |
2488 KB |
Output is correct |
3 |
Correct |
0 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2488 KB |
Output is correct |
2 |
Correct |
0 ms |
2488 KB |
Output is correct |
3 |
Correct |
0 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2488 KB |
Output is correct |
2 |
Correct |
0 ms |
2488 KB |
Output is correct |
3 |
Correct |
0 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2488 KB |
Output is correct |
2 |
Correct |
0 ms |
2488 KB |
Output is correct |
3 |
Correct |
0 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2488 KB |
Output is correct |
2 |
Correct |
29 ms |
2488 KB |
Output is correct |
3 |
Correct |
29 ms |
2488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
2488 KB |
Output is correct |
2 |
Correct |
119 ms |
2488 KB |
Output is correct |
3 |
Correct |
199 ms |
2488 KB |
Output is correct |