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>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
int a[2002];
ll dp[2002][2002];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
FOR(i, 1, n + 1) cin >> a[i];
dp[1][n] = 1;
for (int j = n - 1; j; j--) {
FOR(i, 1, n - j + 2) {
if (a[i - 1] >= a[i + j]) dp[i][i + j - 1] += dp[i - 1][i + j - 1];
if (a[i + j] >= a[i - 1]) dp[i][i + j - 1] += dp[i][i + j];
if (dp[i][i + j - 1] >= MOD) dp[i][i + j - 1] -= MOD;
}
}
while (k--) {
int pos;
cin >> pos;
cout << dp[pos][pos] << '\n';
}
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... |