답안 #730008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730008 2023-04-25T05:01:42 Z nguyentunglam Boat (APIO16_boat) C++17
100 / 100
494 ms 4428 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 510, mod = 1e9 + 7;
int l[N], r[N], a[N], b[N], cnt[N << 1], inv[N], f[2][N << 1][N];
int power(int a, int p) {
    if (!p) return 1;
    int tmp = power(a, p >> 1);
    tmp = 1LL * tmp * tmp % mod;
    if (p % 2) return 1LL * tmp * a % mod;
    return tmp;
}
void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}
int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int n; cin >> n;
    vector<int> rrh;
    for(int i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
        rrh.push_back(l[i] - 1);
        rrh.push_back(r[i]);
    }

    sort(rrh.begin(), rrh.end());
    rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin());
    for(int i = 1; i <= n; i++) {
        a[i] = upper_bound(rrh.begin(), rrh.end(), l[i] - 1) - rrh.begin();
        b[i] = upper_bound(rrh.begin(), rrh.end(), r[i]) - rrh.begin();
//        cout << a[i] << " " << b[i] << endl;
    }

    for(int i = 1; i < rrh.size(); i++) cnt[i + 1] = rrh[i] - rrh[i - 1];
//    for(int i = 1; i <= rrh.size(); i++) cout << cnt[i] << " ";
    for(int i = 2; i <= n; i++) inv[i] = power(i, mod - 2);

    int m = rrh.size();
    bool cur = 1;
    for(int i = 1; i <= n; i++) {
        bool pre = cur;
        cur ^= 1;
        for(int j = 1; j <= m; j++) for(int k = 0; k <= i; k++) f[cur][j][k] = f[pre][j][k];
        int prefix = 1;
        for(int j = 1; j <= a[i]; j++) for(int k = 0; k <= min(cnt[j], i); k++) add(prefix, f[pre][j][k]);
        for(int j = a[i] + 1; j <= b[i]; j++) {
            add(f[cur][j][1], 1LL * prefix * cnt[j] % mod);
            add(prefix, f[pre][j][1]);
            for(int k = 2; k <= i; k++) {
                add(f[cur][j][k], 1LL * f[pre][j][k - 1] * (cnt[j] - k + 1) % mod * inv[k] % mod);
                add(prefix, f[pre][j][k]);
            }
        }
    }
    int res = 0;
    for(int j = 2; j <= m; j++) for(int k = 1; k <= n; k++) {
        add(res, f[cur][j][k]);
    }
    cout << res;
}


Compilation message

boat.cpp: In function 'int main()':
boat.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i = 1; i < rrh.size(); i++) cnt[i + 1] = rrh[i] - rrh[i - 1];
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 4332 KB Output is correct
2 Correct 134 ms 4336 KB Output is correct
3 Correct 135 ms 4304 KB Output is correct
4 Correct 126 ms 4308 KB Output is correct
5 Correct 127 ms 4340 KB Output is correct
6 Correct 149 ms 4344 KB Output is correct
7 Correct 144 ms 4332 KB Output is correct
8 Correct 151 ms 4336 KB Output is correct
9 Correct 160 ms 4336 KB Output is correct
10 Correct 147 ms 4336 KB Output is correct
11 Correct 141 ms 4340 KB Output is correct
12 Correct 155 ms 4336 KB Output is correct
13 Correct 159 ms 4332 KB Output is correct
14 Correct 137 ms 4308 KB Output is correct
15 Correct 138 ms 4348 KB Output is correct
16 Correct 22 ms 1108 KB Output is correct
17 Correct 22 ms 1108 KB Output is correct
18 Correct 22 ms 976 KB Output is correct
19 Correct 27 ms 1104 KB Output is correct
20 Correct 22 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 4332 KB Output is correct
2 Correct 134 ms 4336 KB Output is correct
3 Correct 135 ms 4304 KB Output is correct
4 Correct 126 ms 4308 KB Output is correct
5 Correct 127 ms 4340 KB Output is correct
6 Correct 149 ms 4344 KB Output is correct
7 Correct 144 ms 4332 KB Output is correct
8 Correct 151 ms 4336 KB Output is correct
9 Correct 160 ms 4336 KB Output is correct
10 Correct 147 ms 4336 KB Output is correct
11 Correct 141 ms 4340 KB Output is correct
12 Correct 155 ms 4336 KB Output is correct
13 Correct 159 ms 4332 KB Output is correct
14 Correct 137 ms 4308 KB Output is correct
15 Correct 138 ms 4348 KB Output is correct
16 Correct 22 ms 1108 KB Output is correct
17 Correct 22 ms 1108 KB Output is correct
18 Correct 22 ms 976 KB Output is correct
19 Correct 27 ms 1104 KB Output is correct
20 Correct 22 ms 976 KB Output is correct
21 Correct 304 ms 3992 KB Output is correct
22 Correct 353 ms 4036 KB Output is correct
23 Correct 297 ms 3964 KB Output is correct
24 Correct 313 ms 3932 KB Output is correct
25 Correct 320 ms 3944 KB Output is correct
26 Correct 451 ms 3852 KB Output is correct
27 Correct 391 ms 3920 KB Output is correct
28 Correct 434 ms 3848 KB Output is correct
29 Correct 401 ms 3840 KB Output is correct
30 Correct 139 ms 4328 KB Output is correct
31 Correct 140 ms 4348 KB Output is correct
32 Correct 134 ms 4412 KB Output is correct
33 Correct 132 ms 4340 KB Output is correct
34 Correct 155 ms 4320 KB Output is correct
35 Correct 145 ms 4332 KB Output is correct
36 Correct 140 ms 4332 KB Output is correct
37 Correct 115 ms 4344 KB Output is correct
38 Correct 134 ms 4388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 5 ms 1100 KB Output is correct
4 Correct 4 ms 1096 KB Output is correct
5 Correct 4 ms 1108 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 5 ms 1108 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1152 KB Output is correct
14 Correct 4 ms 1108 KB Output is correct
15 Correct 5 ms 1108 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 4332 KB Output is correct
2 Correct 134 ms 4336 KB Output is correct
3 Correct 135 ms 4304 KB Output is correct
4 Correct 126 ms 4308 KB Output is correct
5 Correct 127 ms 4340 KB Output is correct
6 Correct 149 ms 4344 KB Output is correct
7 Correct 144 ms 4332 KB Output is correct
8 Correct 151 ms 4336 KB Output is correct
9 Correct 160 ms 4336 KB Output is correct
10 Correct 147 ms 4336 KB Output is correct
11 Correct 141 ms 4340 KB Output is correct
12 Correct 155 ms 4336 KB Output is correct
13 Correct 159 ms 4332 KB Output is correct
14 Correct 137 ms 4308 KB Output is correct
15 Correct 138 ms 4348 KB Output is correct
16 Correct 22 ms 1108 KB Output is correct
17 Correct 22 ms 1108 KB Output is correct
18 Correct 22 ms 976 KB Output is correct
19 Correct 27 ms 1104 KB Output is correct
20 Correct 22 ms 976 KB Output is correct
21 Correct 304 ms 3992 KB Output is correct
22 Correct 353 ms 4036 KB Output is correct
23 Correct 297 ms 3964 KB Output is correct
24 Correct 313 ms 3932 KB Output is correct
25 Correct 320 ms 3944 KB Output is correct
26 Correct 451 ms 3852 KB Output is correct
27 Correct 391 ms 3920 KB Output is correct
28 Correct 434 ms 3848 KB Output is correct
29 Correct 401 ms 3840 KB Output is correct
30 Correct 139 ms 4328 KB Output is correct
31 Correct 140 ms 4348 KB Output is correct
32 Correct 134 ms 4412 KB Output is correct
33 Correct 132 ms 4340 KB Output is correct
34 Correct 155 ms 4320 KB Output is correct
35 Correct 145 ms 4332 KB Output is correct
36 Correct 140 ms 4332 KB Output is correct
37 Correct 115 ms 4344 KB Output is correct
38 Correct 134 ms 4388 KB Output is correct
39 Correct 5 ms 1108 KB Output is correct
40 Correct 4 ms 1108 KB Output is correct
41 Correct 5 ms 1100 KB Output is correct
42 Correct 4 ms 1096 KB Output is correct
43 Correct 4 ms 1108 KB Output is correct
44 Correct 5 ms 1108 KB Output is correct
45 Correct 5 ms 1108 KB Output is correct
46 Correct 7 ms 1108 KB Output is correct
47 Correct 5 ms 1152 KB Output is correct
48 Correct 5 ms 1108 KB Output is correct
49 Correct 4 ms 1108 KB Output is correct
50 Correct 4 ms 1108 KB Output is correct
51 Correct 4 ms 1152 KB Output is correct
52 Correct 4 ms 1108 KB Output is correct
53 Correct 5 ms 1108 KB Output is correct
54 Correct 3 ms 724 KB Output is correct
55 Correct 3 ms 716 KB Output is correct
56 Correct 3 ms 724 KB Output is correct
57 Correct 3 ms 716 KB Output is correct
58 Correct 3 ms 724 KB Output is correct
59 Correct 378 ms 4308 KB Output is correct
60 Correct 343 ms 4428 KB Output is correct
61 Correct 319 ms 4336 KB Output is correct
62 Correct 412 ms 4336 KB Output is correct
63 Correct 369 ms 4428 KB Output is correct
64 Correct 470 ms 4336 KB Output is correct
65 Correct 469 ms 4308 KB Output is correct
66 Correct 494 ms 4332 KB Output is correct
67 Correct 489 ms 4336 KB Output is correct
68 Correct 450 ms 4336 KB Output is correct
69 Correct 326 ms 4352 KB Output is correct
70 Correct 314 ms 4336 KB Output is correct
71 Correct 330 ms 4340 KB Output is correct
72 Correct 326 ms 4336 KB Output is correct
73 Correct 365 ms 4340 KB Output is correct
74 Correct 61 ms 980 KB Output is correct
75 Correct 59 ms 1112 KB Output is correct
76 Correct 65 ms 984 KB Output is correct
77 Correct 73 ms 980 KB Output is correct
78 Correct 61 ms 980 KB Output is correct