답안 #679468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679468 2023-01-08T10:52:30 Z stevancv Boat (APIO16_boat) C++14
100 / 100
517 ms 4900 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sadd(a, b) a = Add(a, b)
#define smul(a, b) a = Mul(a, b)
using namespace std;
const int N = 500 + 2;
const int mod = 1e9 + 7;
int fak[N], inv[N];
int Add(int a, int b) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}
int Mul(int a, int b) {
    ll c = a; c *= b; c %= mod;
    return c;
}
int Exp(int a, int b) {
    int ans = 1;
    while (b > 0) {
        if (b & 1) smul(ans, a);
        smul(a, a);
        b >>= 1;
    }
    return ans;
}
int koef[2 * N][N], dp[N][2 * N];
bool pos[2 * N][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fak[0] = inv[0] = 1;
    for (int i = 1; i < N; i++) {
        fak[i] = Mul(fak[i - 1], i);
        inv[i] = Exp(fak[i], mod - 2);
    }
    int n; cin >> n;
    vector<int> a(n), b(n), all;
    all.push_back(-1);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        a[i] -= 1;
        all.push_back(a[i]);
        all.push_back(b[i]);
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    int x = all.size();
    for (int i = 1; i < x; i++) {
        int l = all[i] - all[i - 1];
        int prod = 1, p = l;
        for (int j = 1; j <= n; j++) {
            smul(prod, p++);
            koef[i][j] = Mul(prod, inv[j]);
        }
    }
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(all.begin(), all.end(), a[i]) - all.begin();
        b[i] = lower_bound(all.begin(), all.end(), b[i]) - all.begin();
    }
    for (int j = 0; j < x; j++) dp[0][j] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = a[i] + 1; j <= b[i]; j++) {
            int y = 1;
            for (int k = i; k >= 0; k--) {
                sadd(dp[i + 1][j], Mul(dp[k][j - 1], koef[j][y]));
                if (pos[j][k - 1]) y += 1;
            }
            pos[j][i] = 1;
        }
        for (int j = 1; j < x; j++) sadd(dp[i + 1][j], dp[i + 1][j - 1]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) sadd(ans, dp[i][x - 1]);
    cout << ans << en;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4692 KB Output is correct
2 Correct 9 ms 4724 KB Output is correct
3 Correct 8 ms 4692 KB Output is correct
4 Correct 8 ms 4720 KB Output is correct
5 Correct 8 ms 4692 KB Output is correct
6 Correct 7 ms 4692 KB Output is correct
7 Correct 8 ms 4692 KB Output is correct
8 Correct 7 ms 4692 KB Output is correct
9 Correct 7 ms 4692 KB Output is correct
10 Correct 8 ms 4692 KB Output is correct
11 Correct 7 ms 4692 KB Output is correct
12 Correct 7 ms 4692 KB Output is correct
13 Correct 9 ms 4692 KB Output is correct
14 Correct 7 ms 4692 KB Output is correct
15 Correct 7 ms 4720 KB Output is correct
16 Correct 3 ms 2648 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2776 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4692 KB Output is correct
2 Correct 9 ms 4724 KB Output is correct
3 Correct 8 ms 4692 KB Output is correct
4 Correct 8 ms 4720 KB Output is correct
5 Correct 8 ms 4692 KB Output is correct
6 Correct 7 ms 4692 KB Output is correct
7 Correct 8 ms 4692 KB Output is correct
8 Correct 7 ms 4692 KB Output is correct
9 Correct 7 ms 4692 KB Output is correct
10 Correct 8 ms 4692 KB Output is correct
11 Correct 7 ms 4692 KB Output is correct
12 Correct 7 ms 4692 KB Output is correct
13 Correct 9 ms 4692 KB Output is correct
14 Correct 7 ms 4692 KB Output is correct
15 Correct 7 ms 4720 KB Output is correct
16 Correct 3 ms 2648 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2776 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 311 ms 4492 KB Output is correct
22 Correct 295 ms 4476 KB Output is correct
23 Correct 270 ms 4488 KB Output is correct
24 Correct 288 ms 4524 KB Output is correct
25 Correct 290 ms 4408 KB Output is correct
26 Correct 440 ms 4456 KB Output is correct
27 Correct 466 ms 4552 KB Output is correct
28 Correct 448 ms 4448 KB Output is correct
29 Correct 438 ms 4428 KB Output is correct
30 Correct 9 ms 4692 KB Output is correct
31 Correct 10 ms 4708 KB Output is correct
32 Correct 10 ms 4692 KB Output is correct
33 Correct 10 ms 4692 KB Output is correct
34 Correct 10 ms 4696 KB Output is correct
35 Correct 9 ms 4692 KB Output is correct
36 Correct 9 ms 4692 KB Output is correct
37 Correct 9 ms 4692 KB Output is correct
38 Correct 10 ms 4692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1236 KB Output is correct
2 Correct 3 ms 1228 KB Output is correct
3 Correct 4 ms 1120 KB Output is correct
4 Correct 4 ms 1108 KB Output is correct
5 Correct 4 ms 1232 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 5 ms 1108 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
12 Correct 3 ms 1108 KB Output is correct
13 Correct 3 ms 1108 KB Output is correct
14 Correct 5 ms 1108 KB Output is correct
15 Correct 3 ms 1108 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 3 ms 980 KB Output is correct
18 Correct 3 ms 980 KB Output is correct
19 Correct 2 ms 980 KB Output is correct
20 Correct 2 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4692 KB Output is correct
2 Correct 9 ms 4724 KB Output is correct
3 Correct 8 ms 4692 KB Output is correct
4 Correct 8 ms 4720 KB Output is correct
5 Correct 8 ms 4692 KB Output is correct
6 Correct 7 ms 4692 KB Output is correct
7 Correct 8 ms 4692 KB Output is correct
8 Correct 7 ms 4692 KB Output is correct
9 Correct 7 ms 4692 KB Output is correct
10 Correct 8 ms 4692 KB Output is correct
11 Correct 7 ms 4692 KB Output is correct
12 Correct 7 ms 4692 KB Output is correct
13 Correct 9 ms 4692 KB Output is correct
14 Correct 7 ms 4692 KB Output is correct
15 Correct 7 ms 4720 KB Output is correct
16 Correct 3 ms 2648 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2776 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 3 ms 2772 KB Output is correct
21 Correct 311 ms 4492 KB Output is correct
22 Correct 295 ms 4476 KB Output is correct
23 Correct 270 ms 4488 KB Output is correct
24 Correct 288 ms 4524 KB Output is correct
25 Correct 290 ms 4408 KB Output is correct
26 Correct 440 ms 4456 KB Output is correct
27 Correct 466 ms 4552 KB Output is correct
28 Correct 448 ms 4448 KB Output is correct
29 Correct 438 ms 4428 KB Output is correct
30 Correct 9 ms 4692 KB Output is correct
31 Correct 10 ms 4708 KB Output is correct
32 Correct 10 ms 4692 KB Output is correct
33 Correct 10 ms 4692 KB Output is correct
34 Correct 10 ms 4696 KB Output is correct
35 Correct 9 ms 4692 KB Output is correct
36 Correct 9 ms 4692 KB Output is correct
37 Correct 9 ms 4692 KB Output is correct
38 Correct 10 ms 4692 KB Output is correct
39 Correct 4 ms 1236 KB Output is correct
40 Correct 3 ms 1228 KB Output is correct
41 Correct 4 ms 1120 KB Output is correct
42 Correct 4 ms 1108 KB Output is correct
43 Correct 4 ms 1232 KB Output is correct
44 Correct 5 ms 1108 KB Output is correct
45 Correct 5 ms 1108 KB Output is correct
46 Correct 5 ms 1108 KB Output is correct
47 Correct 5 ms 1236 KB Output is correct
48 Correct 6 ms 1108 KB Output is correct
49 Correct 4 ms 1108 KB Output is correct
50 Correct 3 ms 1108 KB Output is correct
51 Correct 3 ms 1108 KB Output is correct
52 Correct 5 ms 1108 KB Output is correct
53 Correct 3 ms 1108 KB Output is correct
54 Correct 3 ms 980 KB Output is correct
55 Correct 3 ms 980 KB Output is correct
56 Correct 3 ms 980 KB Output is correct
57 Correct 2 ms 980 KB Output is correct
58 Correct 2 ms 980 KB Output is correct
59 Correct 318 ms 4676 KB Output is correct
60 Correct 311 ms 4812 KB Output is correct
61 Correct 290 ms 4660 KB Output is correct
62 Correct 330 ms 4644 KB Output is correct
63 Correct 319 ms 4668 KB Output is correct
64 Correct 496 ms 4812 KB Output is correct
65 Correct 502 ms 4856 KB Output is correct
66 Correct 517 ms 4764 KB Output is correct
67 Correct 498 ms 4872 KB Output is correct
68 Correct 504 ms 4900 KB Output is correct
69 Correct 270 ms 4652 KB Output is correct
70 Correct 263 ms 4708 KB Output is correct
71 Correct 258 ms 4688 KB Output is correct
72 Correct 270 ms 4680 KB Output is correct
73 Correct 281 ms 4716 KB Output is correct
74 Correct 63 ms 2720 KB Output is correct
75 Correct 59 ms 2688 KB Output is correct
76 Correct 63 ms 2684 KB Output is correct
77 Correct 61 ms 2764 KB Output is correct
78 Correct 67 ms 2636 KB Output is correct