답안 #165181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165181 2019-11-25T16:21:53 Z dolphingarlic Boat (APIO16_boat) C++14
100 / 100
640 ms 2552 KB
#include <bits/stdc++.h>
using namespace std;

#define MAXN 503
typedef long long ll;

const int MOD = 1e9 + 7;
int N, A[MAXN], B[MAXN], L[MAXN * 2], D[MAXN][MAXN * 2], inv[MAXN];
vector<int> X;

/*
 * D[i][j] = number of increasing subsequence between index 1 ~ i,
             and the largest number is equal or lower than the endpoint of
 interval j
 * inv[i] = modular inverse of integer i (modulo MOD)
 */

int main() {
    inv[1] = 1;
    for (int i = 2; i < MAXN; i++)
        inv[i] = (ll)inv[MOD % i] * (MOD - MOD / i) % MOD;

    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        scanf("%d%d", A + i, B + i);
        X.push_back(A[i]);
        X.push_back(B[i] + 1);
    }

    sort(X.begin(), X.end());
    X.erase(unique(X.begin(), X.end()), X.end());

    for (int i = 1; i <= N; i++) {
        A[i] = upper_bound(X.begin(), X.end(), A[i]) - X.begin();
        B[i] = upper_bound(X.begin(), X.end(), B[i]) - X.begin();
    }

    for (int i = 1; i < X.size(); i++) L[i] = X[i] - X[i - 1];
    for (int i = 0; i < X.size(); i++) D[0][i] = 1;

    for (int i = 1; i <= N; i++) {
        for (int j = A[i]; j <= B[i]; j++) {
            D[i][j] = (ll)L[j] * D[i - 1][j - 1] % MOD;

            int cnt = 1, choose = L[j] - 1;
            for (int k = i - 1; k > 0; k--) {
                if (A[k] <= j && j <= B[k]) {
                    cnt++;
                    choose = (ll)choose * (L[j] + cnt - 2) % MOD * inv[cnt] % MOD;
                    if (!choose) break;

                    D[i][j] = (D[i][j] + (ll)D[k - 1][j - 1] * choose) % MOD;
                }
            }
        }

        D[i][0] = 1;
        for (int j = 1; j < X.size(); j++)
            D[i][j] = ((ll)D[i][j] + D[i - 1][j] + D[i][j - 1] - D[i - 1][j - 1] + MOD) % MOD;
    }

    printf("%d\n", (D[N][X.size() - 1] - 1 + MOD) % MOD);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < X.size(); i++) L[i] = X[i] - X[i - 1];
                     ~~^~~~~~~~~~
boat.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < X.size(); i++) D[0][i] = 1;
                     ~~^~~~~~~~~~
boat.cpp:58:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 1; j < X.size(); j++)
                         ~~^~~~~~~~~~
boat.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
boat.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", A + i, B + i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2296 KB Output is correct
2 Correct 8 ms 2300 KB Output is correct
3 Correct 8 ms 2296 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 8 ms 2296 KB Output is correct
6 Correct 8 ms 2296 KB Output is correct
7 Correct 8 ms 2296 KB Output is correct
8 Correct 8 ms 2300 KB Output is correct
9 Correct 8 ms 2296 KB Output is correct
10 Correct 8 ms 2296 KB Output is correct
11 Correct 8 ms 2296 KB Output is correct
12 Correct 8 ms 2296 KB Output is correct
13 Correct 8 ms 2296 KB Output is correct
14 Correct 8 ms 2296 KB Output is correct
15 Correct 8 ms 2296 KB Output is correct
16 Correct 5 ms 2296 KB Output is correct
17 Correct 5 ms 2296 KB Output is correct
18 Correct 5 ms 2296 KB Output is correct
19 Correct 5 ms 2296 KB Output is correct
20 Correct 5 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2296 KB Output is correct
2 Correct 8 ms 2300 KB Output is correct
3 Correct 8 ms 2296 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 8 ms 2296 KB Output is correct
6 Correct 8 ms 2296 KB Output is correct
7 Correct 8 ms 2296 KB Output is correct
8 Correct 8 ms 2300 KB Output is correct
9 Correct 8 ms 2296 KB Output is correct
10 Correct 8 ms 2296 KB Output is correct
11 Correct 8 ms 2296 KB Output is correct
12 Correct 8 ms 2296 KB Output is correct
13 Correct 8 ms 2296 KB Output is correct
14 Correct 8 ms 2296 KB Output is correct
15 Correct 8 ms 2296 KB Output is correct
16 Correct 5 ms 2296 KB Output is correct
17 Correct 5 ms 2296 KB Output is correct
18 Correct 5 ms 2296 KB Output is correct
19 Correct 5 ms 2296 KB Output is correct
20 Correct 5 ms 2296 KB Output is correct
21 Correct 201 ms 2296 KB Output is correct
22 Correct 193 ms 2308 KB Output is correct
23 Correct 172 ms 2424 KB Output is correct
24 Correct 204 ms 2360 KB Output is correct
25 Correct 199 ms 2296 KB Output is correct
26 Correct 423 ms 2280 KB Output is correct
27 Correct 417 ms 2424 KB Output is correct
28 Correct 441 ms 2436 KB Output is correct
29 Correct 442 ms 2296 KB Output is correct
30 Correct 8 ms 2424 KB Output is correct
31 Correct 8 ms 2296 KB Output is correct
32 Correct 8 ms 2296 KB Output is correct
33 Correct 8 ms 2424 KB Output is correct
34 Correct 8 ms 2296 KB Output is correct
35 Correct 9 ms 2296 KB Output is correct
36 Correct 9 ms 2300 KB Output is correct
37 Correct 9 ms 2324 KB Output is correct
38 Correct 9 ms 2356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 4 ms 888 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 5 ms 760 KB Output is correct
5 Correct 5 ms 760 KB Output is correct
6 Correct 7 ms 760 KB Output is correct
7 Correct 7 ms 760 KB Output is correct
8 Correct 7 ms 760 KB Output is correct
9 Correct 7 ms 760 KB Output is correct
10 Correct 7 ms 760 KB Output is correct
11 Correct 5 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 4 ms 760 KB Output is correct
14 Correct 4 ms 760 KB Output is correct
15 Correct 5 ms 760 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 3 ms 760 KB Output is correct
19 Correct 3 ms 760 KB Output is correct
20 Correct 4 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2296 KB Output is correct
2 Correct 8 ms 2300 KB Output is correct
3 Correct 8 ms 2296 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 8 ms 2296 KB Output is correct
6 Correct 8 ms 2296 KB Output is correct
7 Correct 8 ms 2296 KB Output is correct
8 Correct 8 ms 2300 KB Output is correct
9 Correct 8 ms 2296 KB Output is correct
10 Correct 8 ms 2296 KB Output is correct
11 Correct 8 ms 2296 KB Output is correct
12 Correct 8 ms 2296 KB Output is correct
13 Correct 8 ms 2296 KB Output is correct
14 Correct 8 ms 2296 KB Output is correct
15 Correct 8 ms 2296 KB Output is correct
16 Correct 5 ms 2296 KB Output is correct
17 Correct 5 ms 2296 KB Output is correct
18 Correct 5 ms 2296 KB Output is correct
19 Correct 5 ms 2296 KB Output is correct
20 Correct 5 ms 2296 KB Output is correct
21 Correct 201 ms 2296 KB Output is correct
22 Correct 193 ms 2308 KB Output is correct
23 Correct 172 ms 2424 KB Output is correct
24 Correct 204 ms 2360 KB Output is correct
25 Correct 199 ms 2296 KB Output is correct
26 Correct 423 ms 2280 KB Output is correct
27 Correct 417 ms 2424 KB Output is correct
28 Correct 441 ms 2436 KB Output is correct
29 Correct 442 ms 2296 KB Output is correct
30 Correct 8 ms 2424 KB Output is correct
31 Correct 8 ms 2296 KB Output is correct
32 Correct 8 ms 2296 KB Output is correct
33 Correct 8 ms 2424 KB Output is correct
34 Correct 8 ms 2296 KB Output is correct
35 Correct 9 ms 2296 KB Output is correct
36 Correct 9 ms 2300 KB Output is correct
37 Correct 9 ms 2324 KB Output is correct
38 Correct 9 ms 2356 KB Output is correct
39 Correct 5 ms 760 KB Output is correct
40 Correct 4 ms 888 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 5 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 7 ms 760 KB Output is correct
45 Correct 7 ms 760 KB Output is correct
46 Correct 7 ms 760 KB Output is correct
47 Correct 7 ms 760 KB Output is correct
48 Correct 7 ms 760 KB Output is correct
49 Correct 5 ms 760 KB Output is correct
50 Correct 2 ms 760 KB Output is correct
51 Correct 4 ms 760 KB Output is correct
52 Correct 4 ms 760 KB Output is correct
53 Correct 5 ms 760 KB Output is correct
54 Correct 4 ms 760 KB Output is correct
55 Correct 3 ms 760 KB Output is correct
56 Correct 3 ms 760 KB Output is correct
57 Correct 3 ms 760 KB Output is correct
58 Correct 4 ms 760 KB Output is correct
59 Correct 269 ms 2404 KB Output is correct
60 Correct 243 ms 2276 KB Output is correct
61 Correct 225 ms 2404 KB Output is correct
62 Correct 268 ms 2300 KB Output is correct
63 Correct 248 ms 2424 KB Output is correct
64 Correct 621 ms 2428 KB Output is correct
65 Correct 613 ms 2520 KB Output is correct
66 Correct 640 ms 2424 KB Output is correct
67 Correct 616 ms 2524 KB Output is correct
68 Correct 633 ms 2552 KB Output is correct
69 Correct 221 ms 2268 KB Output is correct
70 Correct 230 ms 2268 KB Output is correct
71 Correct 229 ms 2384 KB Output is correct
72 Correct 361 ms 2420 KB Output is correct
73 Correct 241 ms 2296 KB Output is correct
74 Correct 33 ms 2296 KB Output is correct
75 Correct 31 ms 2296 KB Output is correct
76 Correct 33 ms 2296 KB Output is correct
77 Correct 32 ms 2296 KB Output is correct
78 Correct 35 ms 2296 KB Output is correct