Submission #516315

# Submission time Handle Problem Language Result Execution time Memory
516315 2022-01-21T05:18:31 Z PeppaPig Boat (APIO16_boat) C++14
100 / 100
808 ms 4432 KB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 1005;
const int M = 1e9+7;

long inv[N];

long modpow(long a, long b) {
    long ret = 1;
    for( ; b; b >>= 1) {
        if(b & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}

long mod(long a, int M) {
    while(a >= M) a -= M;
    return a;
}

int n, a[N], b[N];
long dp[N][N];
vector<int> coord;

int main() {
    for(int i = 1; i < N; i++) inv[i] = modpow(i, M-2);
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d %d", a+i, b+i);
        coord.emplace_back(a[i]);
        coord.emplace_back(++b[i]);
    }
    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());
    for(int i = 1; i <= n; i++) {
        a[i] = lower_bound(coord.begin(), coord.end(), a[i]) - coord.begin() + 1;
        b[i] = lower_bound(coord.begin(), coord.end(), b[i]) - coord.begin() + 1;
    }
    for(int i = 0; i < N; i++) dp[0][i] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = a[i]; j < b[i]; j++) {
            long p = coord[j] - coord[j-1], cnt = 1;
            for(int k = i-1; ~k; k--) {
                dp[i][j] = mod(dp[i][j] + (p * dp[k][j-1]) % M, M);
                if(a[k] <= j && j < b[k]) {
                    ++cnt;
                    p = (p * (coord[j] - coord[j-1] + cnt - 1)) % M;
                    p = (p * inv[cnt]) % M;
                }
            }
        }
        for(int j = 1; j < N; j++) dp[i][j] = mod(dp[i][j] + dp[i][j-1], M);
    }
    long ans = 0;
    for(int i = 1; i <= n; i++) ans = mod(ans + dp[i][N-1], M);
    printf("%lld\n", ans);

    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d %d", a+i, b+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4172 KB Output is correct
2 Correct 5 ms 4136 KB Output is correct
3 Correct 5 ms 4172 KB Output is correct
4 Correct 5 ms 4172 KB Output is correct
5 Correct 5 ms 4172 KB Output is correct
6 Correct 6 ms 4204 KB Output is correct
7 Correct 5 ms 4172 KB Output is correct
8 Correct 5 ms 4232 KB Output is correct
9 Correct 5 ms 4156 KB Output is correct
10 Correct 5 ms 4156 KB Output is correct
11 Correct 5 ms 4172 KB Output is correct
12 Correct 4 ms 4172 KB Output is correct
13 Correct 5 ms 4276 KB Output is correct
14 Correct 5 ms 4152 KB Output is correct
15 Correct 5 ms 4136 KB Output is correct
16 Correct 5 ms 4172 KB Output is correct
17 Correct 5 ms 4152 KB Output is correct
18 Correct 5 ms 4172 KB Output is correct
19 Correct 5 ms 4148 KB Output is correct
20 Correct 5 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4172 KB Output is correct
2 Correct 5 ms 4136 KB Output is correct
3 Correct 5 ms 4172 KB Output is correct
4 Correct 5 ms 4172 KB Output is correct
5 Correct 5 ms 4172 KB Output is correct
6 Correct 6 ms 4204 KB Output is correct
7 Correct 5 ms 4172 KB Output is correct
8 Correct 5 ms 4232 KB Output is correct
9 Correct 5 ms 4156 KB Output is correct
10 Correct 5 ms 4156 KB Output is correct
11 Correct 5 ms 4172 KB Output is correct
12 Correct 4 ms 4172 KB Output is correct
13 Correct 5 ms 4276 KB Output is correct
14 Correct 5 ms 4152 KB Output is correct
15 Correct 5 ms 4136 KB Output is correct
16 Correct 5 ms 4172 KB Output is correct
17 Correct 5 ms 4152 KB Output is correct
18 Correct 5 ms 4172 KB Output is correct
19 Correct 5 ms 4148 KB Output is correct
20 Correct 5 ms 4172 KB Output is correct
21 Correct 496 ms 4292 KB Output is correct
22 Correct 466 ms 4432 KB Output is correct
23 Correct 437 ms 4136 KB Output is correct
24 Correct 462 ms 4208 KB Output is correct
25 Correct 453 ms 4268 KB Output is correct
26 Correct 683 ms 4184 KB Output is correct
27 Correct 713 ms 4252 KB Output is correct
28 Correct 706 ms 4280 KB Output is correct
29 Correct 686 ms 4268 KB Output is correct
30 Correct 7 ms 4172 KB Output is correct
31 Correct 7 ms 4172 KB Output is correct
32 Correct 7 ms 4152 KB Output is correct
33 Correct 7 ms 4172 KB Output is correct
34 Correct 6 ms 4156 KB Output is correct
35 Correct 7 ms 4256 KB Output is correct
36 Correct 7 ms 4152 KB Output is correct
37 Correct 7 ms 4172 KB Output is correct
38 Correct 7 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1100 KB Output is correct
2 Correct 5 ms 1008 KB Output is correct
3 Correct 5 ms 1100 KB Output is correct
4 Correct 5 ms 1100 KB Output is correct
5 Correct 6 ms 1008 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 8 ms 1100 KB Output is correct
8 Correct 7 ms 1092 KB Output is correct
9 Correct 9 ms 1092 KB Output is correct
10 Correct 8 ms 1080 KB Output is correct
11 Correct 6 ms 1100 KB Output is correct
12 Correct 4 ms 1100 KB Output is correct
13 Correct 5 ms 1100 KB Output is correct
14 Correct 4 ms 1100 KB Output is correct
15 Correct 5 ms 1096 KB Output is correct
16 Correct 4 ms 1100 KB Output is correct
17 Correct 3 ms 1100 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 3 ms 1100 KB Output is correct
20 Correct 4 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4172 KB Output is correct
2 Correct 5 ms 4136 KB Output is correct
3 Correct 5 ms 4172 KB Output is correct
4 Correct 5 ms 4172 KB Output is correct
5 Correct 5 ms 4172 KB Output is correct
6 Correct 6 ms 4204 KB Output is correct
7 Correct 5 ms 4172 KB Output is correct
8 Correct 5 ms 4232 KB Output is correct
9 Correct 5 ms 4156 KB Output is correct
10 Correct 5 ms 4156 KB Output is correct
11 Correct 5 ms 4172 KB Output is correct
12 Correct 4 ms 4172 KB Output is correct
13 Correct 5 ms 4276 KB Output is correct
14 Correct 5 ms 4152 KB Output is correct
15 Correct 5 ms 4136 KB Output is correct
16 Correct 5 ms 4172 KB Output is correct
17 Correct 5 ms 4152 KB Output is correct
18 Correct 5 ms 4172 KB Output is correct
19 Correct 5 ms 4148 KB Output is correct
20 Correct 5 ms 4172 KB Output is correct
21 Correct 496 ms 4292 KB Output is correct
22 Correct 466 ms 4432 KB Output is correct
23 Correct 437 ms 4136 KB Output is correct
24 Correct 462 ms 4208 KB Output is correct
25 Correct 453 ms 4268 KB Output is correct
26 Correct 683 ms 4184 KB Output is correct
27 Correct 713 ms 4252 KB Output is correct
28 Correct 706 ms 4280 KB Output is correct
29 Correct 686 ms 4268 KB Output is correct
30 Correct 7 ms 4172 KB Output is correct
31 Correct 7 ms 4172 KB Output is correct
32 Correct 7 ms 4152 KB Output is correct
33 Correct 7 ms 4172 KB Output is correct
34 Correct 6 ms 4156 KB Output is correct
35 Correct 7 ms 4256 KB Output is correct
36 Correct 7 ms 4152 KB Output is correct
37 Correct 7 ms 4172 KB Output is correct
38 Correct 7 ms 4172 KB Output is correct
39 Correct 5 ms 1100 KB Output is correct
40 Correct 5 ms 1008 KB Output is correct
41 Correct 5 ms 1100 KB Output is correct
42 Correct 5 ms 1100 KB Output is correct
43 Correct 6 ms 1008 KB Output is correct
44 Correct 8 ms 1100 KB Output is correct
45 Correct 8 ms 1100 KB Output is correct
46 Correct 7 ms 1092 KB Output is correct
47 Correct 9 ms 1092 KB Output is correct
48 Correct 8 ms 1080 KB Output is correct
49 Correct 6 ms 1100 KB Output is correct
50 Correct 4 ms 1100 KB Output is correct
51 Correct 5 ms 1100 KB Output is correct
52 Correct 4 ms 1100 KB Output is correct
53 Correct 5 ms 1096 KB Output is correct
54 Correct 4 ms 1100 KB Output is correct
55 Correct 3 ms 1100 KB Output is correct
56 Correct 3 ms 1100 KB Output is correct
57 Correct 3 ms 1100 KB Output is correct
58 Correct 4 ms 1100 KB Output is correct
59 Correct 513 ms 4252 KB Output is correct
60 Correct 505 ms 4380 KB Output is correct
61 Correct 460 ms 4256 KB Output is correct
62 Correct 519 ms 4224 KB Output is correct
63 Correct 531 ms 4376 KB Output is correct
64 Correct 789 ms 4244 KB Output is correct
65 Correct 808 ms 4144 KB Output is correct
66 Correct 791 ms 4184 KB Output is correct
67 Correct 783 ms 4192 KB Output is correct
68 Correct 798 ms 4372 KB Output is correct
69 Correct 425 ms 4212 KB Output is correct
70 Correct 404 ms 4176 KB Output is correct
71 Correct 433 ms 4312 KB Output is correct
72 Correct 434 ms 4208 KB Output is correct
73 Correct 425 ms 4292 KB Output is correct
74 Correct 101 ms 4164 KB Output is correct
75 Correct 113 ms 4136 KB Output is correct
76 Correct 104 ms 4348 KB Output is correct
77 Correct 99 ms 4172 KB Output is correct
78 Correct 106 ms 4220 KB Output is correct