Submission #679649

# Submission time Handle Problem Language Result Execution time Memory
679649 2023-01-08T20:03:17 Z bebra Boat (APIO16_boat) C++17
36 / 100
356 ms 3308 KB
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

int add(int a, int b) {
    int res = a + b;
    if (res >= MOD) res -= MOD;
    return res;
}

int sub(int a, int b) {
    int res = a - b;
    if (res < 0) res += MOD;
    return res;
}

int mul(long long a, int b) {
    return a * b % MOD;
}

int binpow(int base, int power) {
    int res = 1;
    while (power > 0) {
        if (power & 1) {
            res = mul(res, base);
        }
        base = mul(base, base);
        power >>= 1;
    }
    return res;
}


int choose(int n, int k) {
    int res = 1;
    for (int i = 0; i < k; ++i) {
        res = mul(res, n - i);
        res = mul(res, binpow(i + 1, MOD - 2));
    }
    return res;
}

const int MAX_N = 500 + 1;
int dp[MAX_N][2 * MAX_N];
int c[MAX_N][MAX_N];

int a[MAX_N];
int b[MAX_N];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> p;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
        p.push_back(a[i]);
        p.push_back(b[i] + 1);
    }
    sort(p.begin(), p.end());
    p.resize(unique(p.begin(), p.end()) - p.begin());
    vector<pair<int, int>> segments;
    for (int i = 0; i < (int)p.size() - 1; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (a[j] <= p[i] && p[i + 1] - 1 <= b[j]) {
                segments.emplace_back(p[i], p[i + 1] - 1);
                break;
            }
        }
    }
    int m = segments.size();
    segments.insert(segments.begin(), {-1, -1});
    for (int i = 1; i <= m; ++i) {
        auto [l, r] = segments[i];
        c[i][1] = r - l + 1;
        for (int j = 2; j <= n; ++j) {
            c[i][j] = mul(c[i][j - 1], mul(r - l + j, binpow(j, MOD - 2)));
        }
    }
    for (int j = 0; j <= m; ++j) {
        dp[0][j] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = 1;
        for (int j = 1; j <= m; ++j) {
            auto [l, r] = segments[j];
            dp[i][j] = dp[i][j - 1];
            int cnt = 0;
            for (int k = i; k >= 1; --k) {
                if (a[k] <= l && r <= b[k]) {
                    ++cnt;
                    dp[i][j] = add(dp[i][j], mul(dp[k - 1][j - 1], c[j][cnt]));
                }
            }
        }
    }
    cout << dp[n][m] - 1 << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 185 ms 3276 KB Output is correct
2 Correct 182 ms 3240 KB Output is correct
3 Correct 191 ms 3152 KB Output is correct
4 Correct 179 ms 3296 KB Output is correct
5 Correct 177 ms 3240 KB Output is correct
6 Correct 122 ms 3200 KB Output is correct
7 Correct 125 ms 3236 KB Output is correct
8 Correct 126 ms 3260 KB Output is correct
9 Correct 123 ms 3184 KB Output is correct
10 Correct 123 ms 3276 KB Output is correct
11 Correct 122 ms 3180 KB Output is correct
12 Correct 121 ms 3308 KB Output is correct
13 Correct 120 ms 3212 KB Output is correct
14 Correct 120 ms 3260 KB Output is correct
15 Correct 121 ms 3212 KB Output is correct
16 Correct 37 ms 2380 KB Output is correct
17 Correct 39 ms 2432 KB Output is correct
18 Correct 44 ms 2436 KB Output is correct
19 Correct 40 ms 2596 KB Output is correct
20 Correct 38 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 3276 KB Output is correct
2 Correct 182 ms 3240 KB Output is correct
3 Correct 191 ms 3152 KB Output is correct
4 Correct 179 ms 3296 KB Output is correct
5 Correct 177 ms 3240 KB Output is correct
6 Correct 122 ms 3200 KB Output is correct
7 Correct 125 ms 3236 KB Output is correct
8 Correct 126 ms 3260 KB Output is correct
9 Correct 123 ms 3184 KB Output is correct
10 Correct 123 ms 3276 KB Output is correct
11 Correct 122 ms 3180 KB Output is correct
12 Correct 121 ms 3308 KB Output is correct
13 Correct 120 ms 3212 KB Output is correct
14 Correct 120 ms 3260 KB Output is correct
15 Correct 121 ms 3212 KB Output is correct
16 Correct 37 ms 2380 KB Output is correct
17 Correct 39 ms 2432 KB Output is correct
18 Correct 44 ms 2436 KB Output is correct
19 Correct 40 ms 2596 KB Output is correct
20 Correct 38 ms 2380 KB Output is correct
21 Incorrect 356 ms 3276 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1108 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 6 ms 1096 KB Output is correct
4 Correct 8 ms 1100 KB Output is correct
5 Correct 7 ms 1096 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 7 ms 1096 KB Output is correct
8 Correct 7 ms 1096 KB Output is correct
9 Correct 7 ms 1092 KB Output is correct
10 Correct 7 ms 1108 KB Output is correct
11 Correct 7 ms 1108 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 7 ms 1056 KB Output is correct
14 Correct 6 ms 1048 KB Output is correct
15 Correct 6 ms 1108 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 852 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 4 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 3276 KB Output is correct
2 Correct 182 ms 3240 KB Output is correct
3 Correct 191 ms 3152 KB Output is correct
4 Correct 179 ms 3296 KB Output is correct
5 Correct 177 ms 3240 KB Output is correct
6 Correct 122 ms 3200 KB Output is correct
7 Correct 125 ms 3236 KB Output is correct
8 Correct 126 ms 3260 KB Output is correct
9 Correct 123 ms 3184 KB Output is correct
10 Correct 123 ms 3276 KB Output is correct
11 Correct 122 ms 3180 KB Output is correct
12 Correct 121 ms 3308 KB Output is correct
13 Correct 120 ms 3212 KB Output is correct
14 Correct 120 ms 3260 KB Output is correct
15 Correct 121 ms 3212 KB Output is correct
16 Correct 37 ms 2380 KB Output is correct
17 Correct 39 ms 2432 KB Output is correct
18 Correct 44 ms 2436 KB Output is correct
19 Correct 40 ms 2596 KB Output is correct
20 Correct 38 ms 2380 KB Output is correct
21 Incorrect 356 ms 3276 KB Output isn't correct
22 Halted 0 ms 0 KB -