Submission #35802015


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;
using ll = long long;

struct mint {
    int n;
    mint() : n(0) { ; }
    mint(ll m) {
        if (m < 0 || MOD <= m) {
            m %= MOD;

            if (m < 0)
                m += MOD;
        }

        n = m;
    }
    operator int() {
        return n;
    }
};
bool operator==(mint a, mint b) {
    return a.n == b.n;
}
mint operator+=(mint &a, mint b) {
    a.n += b.n;

    if (a.n >= MOD)
        a.n -= MOD;

    return a;
}
mint operator-=(mint &a, mint b) {
    a.n -= b.n;

    if (a.n < 0)
        a.n += MOD;

    return a;
}
mint operator*=(mint &a, mint b) {
    a.n = ((ll)a.n * b.n) % MOD;
    return a;
}
mint operator+(mint a, mint b) {
    return a += b;
}
mint operator-(mint a, mint b) {
    return a -= b;
}
mint operator*(mint a, mint b) {
    return a *= b;
}
template<typename T>
mint operator^(mint a, T n) {
    if (n == 0)
        return mint(1);

    mint res = (a * a) ^ (n / 2);

    if (n % 2)
        res = res * a;

    return res;
}
ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
mint operator/(mint a, mint b) {
    return a * mint(inv(b, MOD));
}
mint operator/=(mint &a, mint b) {
    a = a / b;
    return a;
}

int main() {
    cin.tie(NULL)->ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);

    for (auto &x : v) {
        cin >> x;
        --x;
    }

    auto f = vector(n, vector(n, mint(-1)));
    auto h = vector(n, vector(n, mint(0)));
    vector<vector<int>> rp(n);
    auto pos = vector(n, vector(n, 0));

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (v[j] > v[i])
                rp[i].push_back(j);
        }
    }

    function<mint(int, int)> dfs = [&](int l, int r) {
        if (l > r)
            return f[l][r] = mint(0);

        if (l == r)
            return f[l][r] = mint(1);

        if (f[l][r] != mint(-1))
            return f[l][r];

        mint res = 0;

        for (int i = l + 1; i <= r; ++i) {
            mint now = i == l + 1 ? mint(1) : h[l][i];

            if (!now)
                continue;

            for (auto &j = pos[l][i]; j < rp[i].size() && rp[i][j] <= r; ++j) {
                h[l][rp[i][j]] += now * dfs(i, rp[i][j] - 1);
            }

            res += now * dfs(i, r);
        }

        return f[l][r] = res;
    };

    cout << dfs(0, n - 1) << endl;

    return 0;
}

Submission Info

Submission Time
Task G - Pre-Order
User SkqLiiiao
Language C++ (GCC 9.2.1)
Score 600
Code Size 2464 Byte
Status AC
Exec Time 395 ms
Memory 7284 KiB

Compile Error

./Main.cpp: In lambda function:
./Main.cpp:121:41: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  121 |             for (auto &j = pos[l][i]; j < rp[i].size() && rp[i][j] <= r; ++j) {
      |                                       ~~^~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 35
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 6 ms 3464 KiB
example_01.txt AC 2 ms 3540 KiB
hand_00.txt AC 395 ms 7284 KiB
hand_01.txt AC 9 ms 6624 KiB
hand_02.txt AC 2 ms 3500 KiB
random_00.txt AC 174 ms 6656 KiB
random_01.txt AC 2 ms 3600 KiB
random_02.txt AC 133 ms 5988 KiB
random_03.txt AC 82 ms 5464 KiB
random_04.txt AC 8 ms 3820 KiB
random_05.txt AC 9 ms 3764 KiB
random_06.txt AC 10 ms 3616 KiB
random_07.txt AC 4 ms 3668 KiB
random_08.txt AC 134 ms 6088 KiB
random_09.txt AC 13 ms 3932 KiB
random_10.txt AC 295 ms 6640 KiB
random_11.txt AC 282 ms 6536 KiB
random_12.txt AC 318 ms 6892 KiB
random_13.txt AC 331 ms 6892 KiB
random_14.txt AC 385 ms 7248 KiB
random_15.txt AC 305 ms 6784 KiB
random_16.txt AC 295 ms 6648 KiB
random_17.txt AC 297 ms 6712 KiB
random_18.txt AC 356 ms 7140 KiB
random_19.txt AC 386 ms 7272 KiB
random_20.txt AC 213 ms 6772 KiB
random_21.txt AC 191 ms 6856 KiB
random_22.txt AC 284 ms 6880 KiB
random_23.txt AC 213 ms 6944 KiB
random_24.txt AC 201 ms 6912 KiB
random_25.txt AC 83 ms 6392 KiB
random_26.txt AC 167 ms 6748 KiB
random_27.txt AC 187 ms 6832 KiB
random_28.txt AC 123 ms 6712 KiB
random_29.txt AC 41 ms 6460 KiB