Submission #223746

#TimeUsernameProblemLanguageResultExecution timeMemory
223746dolphingarlicŽarulje (COI15_zarulje)C++14
22 / 100
38 ms23160 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...