Submission #896466

# Submission time Handle Problem Language Result Execution time Memory
896466 2024-01-01T13:54:12 Z Alcabel Žarulje (COI15_zarulje) C++17
22 / 100
299 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

struct Modint {
    int x;
    Modint() {
        x = 0;
    }
    Modint(int _x) {
        while (_x >= mod) {
            _x -= mod;
        }
        while (_x < 0) {
            _x += mod;
        }
        x = _x;
    }
    Modint(long long _x) {
        if (_x >= mod || _x <= -mod) {
            _x %= mod;
        }
        if (_x < 0) {
            _x += mod;
        }
        x = _x;
    }
    Modint operator+(const Modint& other) const {
        return Modint(x + other.x);
    }
    Modint operator*(const Modint& other) const {
        return Modint(x * 1ll * other.x);
    }
    void operator+=(const Modint& other) {
        *this = *this + other;
    }
    void operator*=(const Modint& other) {
        *this = *this * other;
    }
    Modint operator^(long long p) const {
        Modint res = 1, tmp = x;
        while (p > 0) {
            if (p & 1) {
                res *= tmp;
            }
            tmp *= tmp;
            p >>= 1;
        }
        return res;
    }
    Modint operator/(const Modint& other) const {
        return *this * (other ^ (mod - 2));
    }
    void operator/=(const Modint& other) {
        *this = *this / other;
    }
    ~Modint() {}
};

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<Modint>> dp(n + 1, vector<Modint>(n + 1));
    dp[0][n] = 1;
    for (int len = n - 1; len >= 1; --len) {
        for (int l = 0; l + len <= n; ++l) {
            int r = l + len;
            if (l == 0) {
                dp[l][r] = dp[l][r + 1];
            } else if (r == n) {
                dp[l][r] = dp[l - 1][r];
            } else {
                if (a[l - 1] > a[r]) {
                    dp[l][r] = dp[l - 1][r];
                } else if (a[l - 1] < a[r]) {
                    dp[l][r] = dp[l][r + 1];
                } else {
                    dp[l][r] = dp[l - 1][r] + dp[l][r + 1];
                }
            }
        }
    }
    while (k--) {
        int pos;
        cin >> pos;
        --pos;
        cout << dp[pos][pos + 1].x << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef LOCALa
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        cerr << "-----------\n";
        cout << "-----------\n";
    }
#else
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
#endif

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 4188 KB Output is correct
3 Correct 21 ms 16228 KB Output is correct
4 Correct 22 ms 16220 KB Output is correct
5 Correct 21 ms 15964 KB Output is correct
6 Correct 19 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 299 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 4188 KB Output is correct
3 Correct 21 ms 16228 KB Output is correct
4 Correct 22 ms 16220 KB Output is correct
5 Correct 21 ms 15964 KB Output is correct
6 Correct 19 ms 16220 KB Output is correct
7 Runtime error 299 ms 524288 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -