Submission #679196

# Submission time Handle Problem Language Result Execution time Memory
679196 2023-01-07T17:05:27 Z bebra Boat (APIO16_boat) C++17
9 / 100
2000 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

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


struct Seg {
    int l;
    int r;

    bool empty() const {
        return r - l + 1 <= 0;
    }

    friend Seg intersect(const Seg& lhs, const Seg& rhs) {
        return {max(lhs.l, rhs.l), min(lhs.r, rhs.r)};
    }
};


const int MOD = 1e9 + 7;
const int INV2 = 500000004;

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

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

const int MAX_N = 500 + 1;
Seg segs[MAX_N];
int dp[MAX_N];


int solve(int l, int r, int pos) {
    if (r - l + 1 <= 0) {
        return 0;
    }
    int res = 0;
    for (int i = pos; i >= 0; --i) {
        if (r < segs[i].l) {
            continue;
        }
        if (l > segs[i].r) {
            res = add(res, mul(dp[i], r - l + 1));
            continue;
        }
        auto [l1, r1] = intersect(Seg{l, r}, segs[i]);
        res = add(res, mul(r - r1, dp[i]));
        res = add(res, mul(solve(l1, r1, i - 1), mul(r1 - l1, INV2)));
        res = add(res, mul(solve(segs[i].l, l1 - 1, i - 1), r1 - l + 1));
    }
    return res;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> segs[i].l >> segs[i].r;
    }
    segs[0] = {-1, -1};
    dp[0] = 1;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        dp[i] = solve(segs[i].l, segs[i].r, i - 1);
        dbg(dp[i]);
        ans = add(ans, dp[i]);
    }
    cout << ans << '\n';
    return 0;
}


/*
2
3 4
1 6

*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 336 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 13 ms 336 KB Output is correct
17 Correct 31 ms 340 KB Output is correct
18 Correct 20 ms 340 KB Output is correct
19 Correct 16 ms 340 KB Output is correct
20 Correct 12 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 336 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 13 ms 336 KB Output is correct
17 Correct 31 ms 340 KB Output is correct
18 Correct 20 ms 340 KB Output is correct
19 Correct 16 ms 340 KB Output is correct
20 Correct 12 ms 340 KB Output is correct
21 Execution timed out 2088 ms 216 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2097 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 336 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 13 ms 336 KB Output is correct
17 Correct 31 ms 340 KB Output is correct
18 Correct 20 ms 340 KB Output is correct
19 Correct 16 ms 340 KB Output is correct
20 Correct 12 ms 340 KB Output is correct
21 Execution timed out 2088 ms 216 KB Time limit exceeded
22 Halted 0 ms 0 KB -