답안 #736255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736255 2023-05-05T11:17:19 Z vjudge1 Boat (APIO16_boat) C++17
100 / 100
375 ms 7240 KB
#include <bits/stdc++.h>
using namespace std;

int f[1000][501];
int a[500], b[500], cnt[1000];
int fact[501], ifact[501];
const int MOD = 1e9 + 7;
int lC[1000][501];
int C[501][501];
int g[501][1000];

inline int Power(int a, int b) {
        int64_t res = 1;
        for (; b; b >>= 1, a = 1ll * a * a % MOD) {
                if (b & 1) (res *= a) %= MOD;
        }
        return res;
}

int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int n;
        cin >> n;
        /// small nCk
        for (int i = 0; i <= n; i++) C[i][0] = C[i][i] = 1;
        for (int i = 0; i <= n; i++) {
                for (int j = 1; j < i; j++) {
                        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
                        if (C[i][j] >= MOD) C[i][j] -= MOD;
                }
        }
        /// calc ifact
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = 1ll * fact[i - 1] * i % MOD;
        ifact[n] = Power(fact[n], MOD - 2);
        for (int i = n; i >= 1; i--) ifact[i - 1] = 1ll * ifact[i] * i % MOD;
        /// input
        for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
        vector<int> point;
        point.reserve(n * 2);
        for (int i = 0; i < n; i++) point.emplace_back(a[i]);
        for (int i = 0; i < n; i++) point.emplace_back(b[i] + 1);
        sort(point.begin(), point.end());
        point.resize(unique(point.begin(), point.end()) - point.begin());
        assert(point.size() <= n * 2);
        int m = point.size() - 1;
        vector<int> range(m);
        for (int i = 0; i < m; i++) range[i] = point[i + 1] - point[i];
        for (int i = 0; i < n; i++) a[i] = lower_bound(point.begin(), point.end(), a[i]) - point.begin();
        for (int i = 0; i < n; i++) b[i] = lower_bound(point.begin(), point.end(), b[i] + 1) - point.begin();
        for (int i = 0; i < n; i++) {
                cnt[a[i]]++;
                cnt[b[i]]--;
        }
        for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
        /// large nCk
        for (int i = 0; i < m; i++) {
                lC[i][0] = 1;
                for (int j = 1, k = range[i]; j <= cnt[i]; j++, k--) lC[i][j] = 1ll * lC[i][j - 1] * k % MOD;
                for (int j = 1; j <= cnt[i]; j++) lC[i][j] = 1ll * lC[i][j] * ifact[j] % MOD;
        }
        /// calc f
        for (int i = 0; i < m; i++) {
                for (int j = 1; j <= cnt[i]; j++) {
                        for (int k = 1; k <= j; k++) {
                                f[i][j] += 1ll * lC[i][k] * C[j - 1][k - 1] % MOD;
                                if (f[i][j] >= MOD) f[i][j] -= MOD;
                        }
                }
        }
        for (int i = 0; i < m; i++) g[0][i] = 1;
        for (int i = 0; i < n; i++) {
                for (int j = a[i]; j < b[i]; j++) {
                        for (int k = i, z = 0; k >= 0; k--) {
                                z += a[k] <= j && j < b[k];
                                int x = j ? g[k][j - 1] : (k == 0);
                                if (x != 0) {
                                        g[i + 1][j] += 1ll * x * f[j][z] % MOD;
                                        if (g[i + 1][j] >= MOD) g[i + 1][j] -= MOD;
                                }
                        }
                }

                for (int j = a[i] + 1; j < m; j++) {
                        g[i + 1][j] += g[i + 1][j - 1];
                        if (g[i + 1][j] >= MOD) g[i + 1][j] -= MOD;
                }
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
                res += g[i][m - 1];
                if (res >= MOD) res -= MOD;
        }
        cout << res;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from boat.cpp:1:
boat.cpp: In function 'int main()':
boat.cpp:46:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         assert(point.size() <= n * 2);
      |                ~~~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7124 KB Output is correct
2 Correct 6 ms 7204 KB Output is correct
3 Correct 6 ms 7124 KB Output is correct
4 Correct 6 ms 7124 KB Output is correct
5 Correct 7 ms 7124 KB Output is correct
6 Correct 6 ms 7124 KB Output is correct
7 Correct 6 ms 7124 KB Output is correct
8 Correct 7 ms 7204 KB Output is correct
9 Correct 5 ms 7180 KB Output is correct
10 Correct 6 ms 7096 KB Output is correct
11 Correct 7 ms 7124 KB Output is correct
12 Correct 6 ms 7124 KB Output is correct
13 Correct 6 ms 7124 KB Output is correct
14 Correct 6 ms 7208 KB Output is correct
15 Correct 6 ms 7148 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 3924 KB Output is correct
18 Correct 3 ms 3924 KB Output is correct
19 Correct 4 ms 3924 KB Output is correct
20 Correct 4 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7124 KB Output is correct
2 Correct 6 ms 7204 KB Output is correct
3 Correct 6 ms 7124 KB Output is correct
4 Correct 6 ms 7124 KB Output is correct
5 Correct 7 ms 7124 KB Output is correct
6 Correct 6 ms 7124 KB Output is correct
7 Correct 6 ms 7124 KB Output is correct
8 Correct 7 ms 7204 KB Output is correct
9 Correct 5 ms 7180 KB Output is correct
10 Correct 6 ms 7096 KB Output is correct
11 Correct 7 ms 7124 KB Output is correct
12 Correct 6 ms 7124 KB Output is correct
13 Correct 6 ms 7124 KB Output is correct
14 Correct 6 ms 7208 KB Output is correct
15 Correct 6 ms 7148 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 3924 KB Output is correct
18 Correct 3 ms 3924 KB Output is correct
19 Correct 4 ms 3924 KB Output is correct
20 Correct 4 ms 3924 KB Output is correct
21 Correct 199 ms 6812 KB Output is correct
22 Correct 183 ms 6892 KB Output is correct
23 Correct 167 ms 6732 KB Output is correct
24 Correct 186 ms 6832 KB Output is correct
25 Correct 183 ms 6788 KB Output is correct
26 Correct 319 ms 6708 KB Output is correct
27 Correct 341 ms 6708 KB Output is correct
28 Correct 320 ms 6616 KB Output is correct
29 Correct 323 ms 6656 KB Output is correct
30 Correct 7 ms 7124 KB Output is correct
31 Correct 6 ms 7124 KB Output is correct
32 Correct 7 ms 7152 KB Output is correct
33 Correct 7 ms 7108 KB Output is correct
34 Correct 7 ms 7124 KB Output is correct
35 Correct 7 ms 7100 KB Output is correct
36 Correct 7 ms 7124 KB Output is correct
37 Correct 7 ms 7124 KB Output is correct
38 Correct 7 ms 7124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1620 KB Output is correct
2 Correct 4 ms 1620 KB Output is correct
3 Correct 3 ms 1620 KB Output is correct
4 Correct 3 ms 1620 KB Output is correct
5 Correct 3 ms 1708 KB Output is correct
6 Correct 4 ms 1608 KB Output is correct
7 Correct 5 ms 1620 KB Output is correct
8 Correct 5 ms 1620 KB Output is correct
9 Correct 4 ms 1676 KB Output is correct
10 Correct 4 ms 1620 KB Output is correct
11 Correct 3 ms 1620 KB Output is correct
12 Correct 3 ms 1620 KB Output is correct
13 Correct 3 ms 1620 KB Output is correct
14 Correct 3 ms 1620 KB Output is correct
15 Correct 3 ms 1608 KB Output is correct
16 Correct 2 ms 1348 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 2 ms 1364 KB Output is correct
19 Correct 2 ms 1364 KB Output is correct
20 Correct 2 ms 1348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7124 KB Output is correct
2 Correct 6 ms 7204 KB Output is correct
3 Correct 6 ms 7124 KB Output is correct
4 Correct 6 ms 7124 KB Output is correct
5 Correct 7 ms 7124 KB Output is correct
6 Correct 6 ms 7124 KB Output is correct
7 Correct 6 ms 7124 KB Output is correct
8 Correct 7 ms 7204 KB Output is correct
9 Correct 5 ms 7180 KB Output is correct
10 Correct 6 ms 7096 KB Output is correct
11 Correct 7 ms 7124 KB Output is correct
12 Correct 6 ms 7124 KB Output is correct
13 Correct 6 ms 7124 KB Output is correct
14 Correct 6 ms 7208 KB Output is correct
15 Correct 6 ms 7148 KB Output is correct
16 Correct 3 ms 3924 KB Output is correct
17 Correct 3 ms 3924 KB Output is correct
18 Correct 3 ms 3924 KB Output is correct
19 Correct 4 ms 3924 KB Output is correct
20 Correct 4 ms 3924 KB Output is correct
21 Correct 199 ms 6812 KB Output is correct
22 Correct 183 ms 6892 KB Output is correct
23 Correct 167 ms 6732 KB Output is correct
24 Correct 186 ms 6832 KB Output is correct
25 Correct 183 ms 6788 KB Output is correct
26 Correct 319 ms 6708 KB Output is correct
27 Correct 341 ms 6708 KB Output is correct
28 Correct 320 ms 6616 KB Output is correct
29 Correct 323 ms 6656 KB Output is correct
30 Correct 7 ms 7124 KB Output is correct
31 Correct 6 ms 7124 KB Output is correct
32 Correct 7 ms 7152 KB Output is correct
33 Correct 7 ms 7108 KB Output is correct
34 Correct 7 ms 7124 KB Output is correct
35 Correct 7 ms 7100 KB Output is correct
36 Correct 7 ms 7124 KB Output is correct
37 Correct 7 ms 7124 KB Output is correct
38 Correct 7 ms 7124 KB Output is correct
39 Correct 3 ms 1620 KB Output is correct
40 Correct 4 ms 1620 KB Output is correct
41 Correct 3 ms 1620 KB Output is correct
42 Correct 3 ms 1620 KB Output is correct
43 Correct 3 ms 1708 KB Output is correct
44 Correct 4 ms 1608 KB Output is correct
45 Correct 5 ms 1620 KB Output is correct
46 Correct 5 ms 1620 KB Output is correct
47 Correct 4 ms 1676 KB Output is correct
48 Correct 4 ms 1620 KB Output is correct
49 Correct 3 ms 1620 KB Output is correct
50 Correct 3 ms 1620 KB Output is correct
51 Correct 3 ms 1620 KB Output is correct
52 Correct 3 ms 1620 KB Output is correct
53 Correct 3 ms 1608 KB Output is correct
54 Correct 2 ms 1348 KB Output is correct
55 Correct 2 ms 1364 KB Output is correct
56 Correct 2 ms 1364 KB Output is correct
57 Correct 2 ms 1364 KB Output is correct
58 Correct 2 ms 1348 KB Output is correct
59 Correct 211 ms 7092 KB Output is correct
60 Correct 192 ms 7180 KB Output is correct
61 Correct 179 ms 7084 KB Output is correct
62 Correct 209 ms 7240 KB Output is correct
63 Correct 203 ms 7160 KB Output is correct
64 Correct 362 ms 7188 KB Output is correct
65 Correct 375 ms 7168 KB Output is correct
66 Correct 363 ms 7160 KB Output is correct
67 Correct 375 ms 7152 KB Output is correct
68 Correct 375 ms 7164 KB Output is correct
69 Correct 188 ms 7116 KB Output is correct
70 Correct 178 ms 7132 KB Output is correct
71 Correct 175 ms 7196 KB Output is correct
72 Correct 187 ms 7200 KB Output is correct
73 Correct 189 ms 7200 KB Output is correct
74 Correct 45 ms 3976 KB Output is correct
75 Correct 44 ms 3940 KB Output is correct
76 Correct 45 ms 3936 KB Output is correct
77 Correct 45 ms 3912 KB Output is correct
78 Correct 46 ms 3888 KB Output is correct