#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int add (int a, int b) {
a += b; if (a >= MOD) a -= MOD;
return a;
}
int dp[2001][2001];
int n, k, a[2002];
void solve () {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int r = n; r >= 1; r--) {
for (int l = 1; l <= r; l++) {
if (l == 1 && r == n) {
dp[l][r] = 1;
continue;
}
int x = max(a[l - 1], a[r + 1]);
if (a[l - 1] == x) dp[l][r] = add(dp[l][r], dp[l - 1][r]);
if (a[r + 1] == x) dp[l][r] = add(dp[l][r], dp[l][r + 1]);
}
}
while (k--) {
int x; cin >> x;
cout << dp[x][x] << ' ';
}
}
signed main () {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1112 KB |
Output is correct |
2 |
Correct |
4 ms |
6236 KB |
Output is correct |
3 |
Correct |
16 ms |
14252 KB |
Output is correct |
4 |
Correct |
14 ms |
14172 KB |
Output is correct |
5 |
Correct |
14 ms |
14168 KB |
Output is correct |
6 |
Correct |
14 ms |
14172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1112 KB |
Output is correct |
2 |
Correct |
4 ms |
6236 KB |
Output is correct |
3 |
Correct |
16 ms |
14252 KB |
Output is correct |
4 |
Correct |
14 ms |
14172 KB |
Output is correct |
5 |
Correct |
14 ms |
14168 KB |
Output is correct |
6 |
Correct |
14 ms |
14172 KB |
Output is correct |
7 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |