Submission #202589

# Submission time Handle Problem Language Result Execution time Memory
202589 2020-02-17T08:09:37 Z pr3pony Boat (APIO16_boat) C++14
100 / 100
438 ms 4472 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 505, MOD = 1e9 + 7;
typedef long long ll;
vector<int> val;
typedef array<int, 2> ar;
ar p[N];
ll dp[2 * N][N], inv[N];
int main()
{
    int n;
    cin >> n;
    val = {-1};
    for (int i = 1; i <= n; ++i) {
        cin >> p[i][0] >> p[i][1];
        ++p[i][1];
        val.push_back(p[i][0]);
        val.push_back(p[i][1]);
    }
    sort(val.begin(), val.end());
    val.resize(unique(val.begin(), val.end()) - val.begin());
    int w = val.size();

    inv[1] = 1;
    for (int i = 2; i <= n; ++i)
        inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;

    for (int i = 0; i < w; ++i)
        dp[i][0] = 1;
    for (int b = 1; b <= n; ++b) {
        for (int i = w - 1; i > 0; --i) 
            if (p[b][0] <= val[i - 1] && val[i] <= p[b][1]) {
                int cn = val[i] - val[i - 1];
                for (int j = min(cn, b); j >= 1; --j)
                    (dp[i][j] += dp[i][j - 1] * (cn - j + 1) % MOD * inv[j]) %= MOD;
            }
        for (int i = 1; i <= w; ++i)
            dp[i][0] = accumulate(dp[i - 1], dp[i - 1] + n + 1, 0ll) % MOD;
    }
    cout << (dp[w][0] + MOD - 1) % MOD << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 156 ms 4344 KB Output is correct
2 Correct 158 ms 4344 KB Output is correct
3 Correct 157 ms 4216 KB Output is correct
4 Correct 156 ms 4472 KB Output is correct
5 Correct 159 ms 4340 KB Output is correct
6 Correct 151 ms 4344 KB Output is correct
7 Correct 153 ms 4216 KB Output is correct
8 Correct 163 ms 4344 KB Output is correct
9 Correct 152 ms 4216 KB Output is correct
10 Correct 157 ms 4340 KB Output is correct
11 Correct 153 ms 4216 KB Output is correct
12 Correct 161 ms 4344 KB Output is correct
13 Correct 154 ms 4216 KB Output is correct
14 Correct 151 ms 4216 KB Output is correct
15 Correct 157 ms 4344 KB Output is correct
16 Correct 31 ms 1016 KB Output is correct
17 Correct 33 ms 1016 KB Output is correct
18 Correct 32 ms 1016 KB Output is correct
19 Correct 33 ms 1144 KB Output is correct
20 Correct 32 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 4344 KB Output is correct
2 Correct 158 ms 4344 KB Output is correct
3 Correct 157 ms 4216 KB Output is correct
4 Correct 156 ms 4472 KB Output is correct
5 Correct 159 ms 4340 KB Output is correct
6 Correct 151 ms 4344 KB Output is correct
7 Correct 153 ms 4216 KB Output is correct
8 Correct 163 ms 4344 KB Output is correct
9 Correct 152 ms 4216 KB Output is correct
10 Correct 157 ms 4340 KB Output is correct
11 Correct 153 ms 4216 KB Output is correct
12 Correct 161 ms 4344 KB Output is correct
13 Correct 154 ms 4216 KB Output is correct
14 Correct 151 ms 4216 KB Output is correct
15 Correct 157 ms 4344 KB Output is correct
16 Correct 31 ms 1016 KB Output is correct
17 Correct 33 ms 1016 KB Output is correct
18 Correct 32 ms 1016 KB Output is correct
19 Correct 33 ms 1144 KB Output is correct
20 Correct 32 ms 1016 KB Output is correct
21 Correct 149 ms 3960 KB Output is correct
22 Correct 154 ms 4172 KB Output is correct
23 Correct 144 ms 3960 KB Output is correct
24 Correct 145 ms 3832 KB Output is correct
25 Correct 155 ms 3960 KB Output is correct
26 Correct 144 ms 3960 KB Output is correct
27 Correct 146 ms 3832 KB Output is correct
28 Correct 141 ms 3832 KB Output is correct
29 Correct 144 ms 3844 KB Output is correct
30 Correct 154 ms 4216 KB Output is correct
31 Correct 154 ms 4216 KB Output is correct
32 Correct 155 ms 4216 KB Output is correct
33 Correct 155 ms 4216 KB Output is correct
34 Correct 151 ms 4216 KB Output is correct
35 Correct 155 ms 4216 KB Output is correct
36 Correct 155 ms 4216 KB Output is correct
37 Correct 158 ms 4216 KB Output is correct
38 Correct 156 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1016 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
3 Correct 10 ms 1144 KB Output is correct
4 Correct 8 ms 1144 KB Output is correct
5 Correct 9 ms 1148 KB Output is correct
6 Correct 10 ms 1144 KB Output is correct
7 Correct 9 ms 1148 KB Output is correct
8 Correct 9 ms 1144 KB Output is correct
9 Correct 9 ms 1144 KB Output is correct
10 Correct 9 ms 1144 KB Output is correct
11 Correct 9 ms 1144 KB Output is correct
12 Correct 8 ms 1144 KB Output is correct
13 Correct 8 ms 1144 KB Output is correct
14 Correct 8 ms 1144 KB Output is correct
15 Correct 8 ms 1144 KB Output is correct
16 Correct 7 ms 760 KB Output is correct
17 Correct 6 ms 760 KB Output is correct
18 Correct 7 ms 760 KB Output is correct
19 Correct 7 ms 760 KB Output is correct
20 Correct 7 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 4344 KB Output is correct
2 Correct 158 ms 4344 KB Output is correct
3 Correct 157 ms 4216 KB Output is correct
4 Correct 156 ms 4472 KB Output is correct
5 Correct 159 ms 4340 KB Output is correct
6 Correct 151 ms 4344 KB Output is correct
7 Correct 153 ms 4216 KB Output is correct
8 Correct 163 ms 4344 KB Output is correct
9 Correct 152 ms 4216 KB Output is correct
10 Correct 157 ms 4340 KB Output is correct
11 Correct 153 ms 4216 KB Output is correct
12 Correct 161 ms 4344 KB Output is correct
13 Correct 154 ms 4216 KB Output is correct
14 Correct 151 ms 4216 KB Output is correct
15 Correct 157 ms 4344 KB Output is correct
16 Correct 31 ms 1016 KB Output is correct
17 Correct 33 ms 1016 KB Output is correct
18 Correct 32 ms 1016 KB Output is correct
19 Correct 33 ms 1144 KB Output is correct
20 Correct 32 ms 1016 KB Output is correct
21 Correct 149 ms 3960 KB Output is correct
22 Correct 154 ms 4172 KB Output is correct
23 Correct 144 ms 3960 KB Output is correct
24 Correct 145 ms 3832 KB Output is correct
25 Correct 155 ms 3960 KB Output is correct
26 Correct 144 ms 3960 KB Output is correct
27 Correct 146 ms 3832 KB Output is correct
28 Correct 141 ms 3832 KB Output is correct
29 Correct 144 ms 3844 KB Output is correct
30 Correct 154 ms 4216 KB Output is correct
31 Correct 154 ms 4216 KB Output is correct
32 Correct 155 ms 4216 KB Output is correct
33 Correct 155 ms 4216 KB Output is correct
34 Correct 151 ms 4216 KB Output is correct
35 Correct 155 ms 4216 KB Output is correct
36 Correct 155 ms 4216 KB Output is correct
37 Correct 158 ms 4216 KB Output is correct
38 Correct 156 ms 4216 KB Output is correct
39 Correct 8 ms 1016 KB Output is correct
40 Correct 8 ms 1144 KB Output is correct
41 Correct 10 ms 1144 KB Output is correct
42 Correct 8 ms 1144 KB Output is correct
43 Correct 9 ms 1148 KB Output is correct
44 Correct 10 ms 1144 KB Output is correct
45 Correct 9 ms 1148 KB Output is correct
46 Correct 9 ms 1144 KB Output is correct
47 Correct 9 ms 1144 KB Output is correct
48 Correct 9 ms 1144 KB Output is correct
49 Correct 9 ms 1144 KB Output is correct
50 Correct 8 ms 1144 KB Output is correct
51 Correct 8 ms 1144 KB Output is correct
52 Correct 8 ms 1144 KB Output is correct
53 Correct 8 ms 1144 KB Output is correct
54 Correct 7 ms 760 KB Output is correct
55 Correct 6 ms 760 KB Output is correct
56 Correct 7 ms 760 KB Output is correct
57 Correct 7 ms 760 KB Output is correct
58 Correct 7 ms 760 KB Output is correct
59 Correct 343 ms 4472 KB Output is correct
60 Correct 336 ms 4348 KB Output is correct
61 Correct 335 ms 4472 KB Output is correct
62 Correct 350 ms 4344 KB Output is correct
63 Correct 335 ms 4344 KB Output is correct
64 Correct 408 ms 4344 KB Output is correct
65 Correct 438 ms 4348 KB Output is correct
66 Correct 425 ms 4348 KB Output is correct
67 Correct 427 ms 4472 KB Output is correct
68 Correct 414 ms 4348 KB Output is correct
69 Correct 302 ms 4384 KB Output is correct
70 Correct 289 ms 4344 KB Output is correct
71 Correct 315 ms 4344 KB Output is correct
72 Correct 292 ms 4344 KB Output is correct
73 Correct 310 ms 4344 KB Output is correct
74 Correct 51 ms 1144 KB Output is correct
75 Correct 49 ms 1016 KB Output is correct
76 Correct 50 ms 888 KB Output is correct
77 Correct 50 ms 1016 KB Output is correct
78 Correct 50 ms 1016 KB Output is correct