# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
278537 | 2020-08-21T14:02:10 Z | BeanZ | Boat (APIO16_boat) | C++14 | 592 ms | 4496 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' ll dp[1005][505], inv[2005], l[505], r[505]; const int mod = 1e9 + 7; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("VietCT.INP", "r")){ freopen("VietCT.INP", "r", stdin); freopen("VietCT.OUT", "w", stdout); } ll n; cin >> n; inv[1] = 1; for (int i = 2; i < 2000; i++) inv[i] = (mod / i) * (mod - inv[mod % i]) % mod; vector<ll> val; for (int i = 1; i <= n; i++){ cin >> l[i] >> r[i]; val.push_back(l[i]); r[i]++; val.push_back(r[i]); } sort(val.begin(), val.end()); val.resize(unique(val.begin(), val.end()) - val.begin()); for (int i = 1; i <= n; i++){ l[i] = lower_bound(val.begin(), val.end(), l[i]) - val.begin() + 1; r[i] = lower_bound(val.begin(), val.end(), r[i]) - val.begin() + 1; } dp[0][0] = 1; for (int i = 1; i < val.size(); i++){ dp[i][0] = 1; for (int j = 1; j <= n; j++){ dp[i][j] = dp[i - 1][j]; if (i < l[j] || i >= r[j]) continue; ll s = val[i] - val[i - 1]; ll cnt = 1; ll p = s; for (int k = j - 1; k >= 0; k--){ dp[i][j] = (dp[i][j] + dp[i - 1][k] * p) % mod; if (l[k] <= i && r[k] > i){ p = p * (s + cnt) % mod; p = p * inv[cnt + 1] % mod; cnt++; } } } } ll ans = 0; for (int i = 1; i <= n; i++){ ans = (ans + dp[val.size() - 1][i]) % mod; } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4352 KB | Output is correct |
2 | Correct | 4 ms | 4352 KB | Output is correct |
3 | Correct | 4 ms | 4352 KB | Output is correct |
4 | Correct | 4 ms | 4352 KB | Output is correct |
5 | Correct | 4 ms | 4352 KB | Output is correct |
6 | Correct | 4 ms | 4352 KB | Output is correct |
7 | Correct | 4 ms | 4352 KB | Output is correct |
8 | Correct | 4 ms | 4352 KB | Output is correct |
9 | Correct | 4 ms | 4352 KB | Output is correct |
10 | Correct | 4 ms | 4352 KB | Output is correct |
11 | Correct | 4 ms | 4352 KB | Output is correct |
12 | Correct | 5 ms | 4352 KB | Output is correct |
13 | Correct | 4 ms | 4352 KB | Output is correct |
14 | Correct | 4 ms | 4352 KB | Output is correct |
15 | Correct | 4 ms | 4352 KB | Output is correct |
16 | Correct | 2 ms | 1024 KB | Output is correct |
17 | Correct | 2 ms | 1152 KB | Output is correct |
18 | Correct | 2 ms | 1152 KB | Output is correct |
19 | Correct | 2 ms | 1152 KB | Output is correct |
20 | Correct | 3 ms | 1152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4352 KB | Output is correct |
2 | Correct | 4 ms | 4352 KB | Output is correct |
3 | Correct | 4 ms | 4352 KB | Output is correct |
4 | Correct | 4 ms | 4352 KB | Output is correct |
5 | Correct | 4 ms | 4352 KB | Output is correct |
6 | Correct | 4 ms | 4352 KB | Output is correct |
7 | Correct | 4 ms | 4352 KB | Output is correct |
8 | Correct | 4 ms | 4352 KB | Output is correct |
9 | Correct | 4 ms | 4352 KB | Output is correct |
10 | Correct | 4 ms | 4352 KB | Output is correct |
11 | Correct | 4 ms | 4352 KB | Output is correct |
12 | Correct | 5 ms | 4352 KB | Output is correct |
13 | Correct | 4 ms | 4352 KB | Output is correct |
14 | Correct | 4 ms | 4352 KB | Output is correct |
15 | Correct | 4 ms | 4352 KB | Output is correct |
16 | Correct | 2 ms | 1024 KB | Output is correct |
17 | Correct | 2 ms | 1152 KB | Output is correct |
18 | Correct | 2 ms | 1152 KB | Output is correct |
19 | Correct | 2 ms | 1152 KB | Output is correct |
20 | Correct | 3 ms | 1152 KB | Output is correct |
21 | Correct | 250 ms | 3960 KB | Output is correct |
22 | Correct | 239 ms | 4140 KB | Output is correct |
23 | Correct | 215 ms | 4004 KB | Output is correct |
24 | Correct | 237 ms | 3960 KB | Output is correct |
25 | Correct | 238 ms | 3960 KB | Output is correct |
26 | Correct | 511 ms | 3832 KB | Output is correct |
27 | Correct | 520 ms | 3960 KB | Output is correct |
28 | Correct | 511 ms | 3832 KB | Output is correct |
29 | Correct | 505 ms | 3832 KB | Output is correct |
30 | Correct | 5 ms | 4352 KB | Output is correct |
31 | Correct | 5 ms | 4352 KB | Output is correct |
32 | Correct | 5 ms | 4352 KB | Output is correct |
33 | Correct | 5 ms | 4352 KB | Output is correct |
34 | Correct | 5 ms | 4352 KB | Output is correct |
35 | Correct | 5 ms | 4352 KB | Output is correct |
36 | Correct | 6 ms | 4352 KB | Output is correct |
37 | Correct | 6 ms | 4352 KB | Output is correct |
38 | Correct | 5 ms | 4352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1152 KB | Output is correct |
2 | Correct | 3 ms | 1152 KB | Output is correct |
3 | Correct | 3 ms | 1152 KB | Output is correct |
4 | Correct | 3 ms | 1152 KB | Output is correct |
5 | Correct | 3 ms | 1152 KB | Output is correct |
6 | Correct | 5 ms | 1152 KB | Output is correct |
7 | Correct | 5 ms | 1152 KB | Output is correct |
8 | Correct | 5 ms | 1152 KB | Output is correct |
9 | Correct | 6 ms | 1152 KB | Output is correct |
10 | Correct | 5 ms | 1152 KB | Output is correct |
11 | Correct | 3 ms | 1152 KB | Output is correct |
12 | Correct | 2 ms | 1152 KB | Output is correct |
13 | Correct | 3 ms | 1152 KB | Output is correct |
14 | Correct | 3 ms | 1152 KB | Output is correct |
15 | Correct | 3 ms | 1152 KB | Output is correct |
16 | Correct | 2 ms | 768 KB | Output is correct |
17 | Correct | 2 ms | 768 KB | Output is correct |
18 | Correct | 2 ms | 768 KB | Output is correct |
19 | Correct | 2 ms | 768 KB | Output is correct |
20 | Correct | 2 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4352 KB | Output is correct |
2 | Correct | 4 ms | 4352 KB | Output is correct |
3 | Correct | 4 ms | 4352 KB | Output is correct |
4 | Correct | 4 ms | 4352 KB | Output is correct |
5 | Correct | 4 ms | 4352 KB | Output is correct |
6 | Correct | 4 ms | 4352 KB | Output is correct |
7 | Correct | 4 ms | 4352 KB | Output is correct |
8 | Correct | 4 ms | 4352 KB | Output is correct |
9 | Correct | 4 ms | 4352 KB | Output is correct |
10 | Correct | 4 ms | 4352 KB | Output is correct |
11 | Correct | 4 ms | 4352 KB | Output is correct |
12 | Correct | 5 ms | 4352 KB | Output is correct |
13 | Correct | 4 ms | 4352 KB | Output is correct |
14 | Correct | 4 ms | 4352 KB | Output is correct |
15 | Correct | 4 ms | 4352 KB | Output is correct |
16 | Correct | 2 ms | 1024 KB | Output is correct |
17 | Correct | 2 ms | 1152 KB | Output is correct |
18 | Correct | 2 ms | 1152 KB | Output is correct |
19 | Correct | 2 ms | 1152 KB | Output is correct |
20 | Correct | 3 ms | 1152 KB | Output is correct |
21 | Correct | 250 ms | 3960 KB | Output is correct |
22 | Correct | 239 ms | 4140 KB | Output is correct |
23 | Correct | 215 ms | 4004 KB | Output is correct |
24 | Correct | 237 ms | 3960 KB | Output is correct |
25 | Correct | 238 ms | 3960 KB | Output is correct |
26 | Correct | 511 ms | 3832 KB | Output is correct |
27 | Correct | 520 ms | 3960 KB | Output is correct |
28 | Correct | 511 ms | 3832 KB | Output is correct |
29 | Correct | 505 ms | 3832 KB | Output is correct |
30 | Correct | 5 ms | 4352 KB | Output is correct |
31 | Correct | 5 ms | 4352 KB | Output is correct |
32 | Correct | 5 ms | 4352 KB | Output is correct |
33 | Correct | 5 ms | 4352 KB | Output is correct |
34 | Correct | 5 ms | 4352 KB | Output is correct |
35 | Correct | 5 ms | 4352 KB | Output is correct |
36 | Correct | 6 ms | 4352 KB | Output is correct |
37 | Correct | 6 ms | 4352 KB | Output is correct |
38 | Correct | 5 ms | 4352 KB | Output is correct |
39 | Correct | 3 ms | 1152 KB | Output is correct |
40 | Correct | 3 ms | 1152 KB | Output is correct |
41 | Correct | 3 ms | 1152 KB | Output is correct |
42 | Correct | 3 ms | 1152 KB | Output is correct |
43 | Correct | 3 ms | 1152 KB | Output is correct |
44 | Correct | 5 ms | 1152 KB | Output is correct |
45 | Correct | 5 ms | 1152 KB | Output is correct |
46 | Correct | 5 ms | 1152 KB | Output is correct |
47 | Correct | 6 ms | 1152 KB | Output is correct |
48 | Correct | 5 ms | 1152 KB | Output is correct |
49 | Correct | 3 ms | 1152 KB | Output is correct |
50 | Correct | 2 ms | 1152 KB | Output is correct |
51 | Correct | 3 ms | 1152 KB | Output is correct |
52 | Correct | 3 ms | 1152 KB | Output is correct |
53 | Correct | 3 ms | 1152 KB | Output is correct |
54 | Correct | 2 ms | 768 KB | Output is correct |
55 | Correct | 2 ms | 768 KB | Output is correct |
56 | Correct | 2 ms | 768 KB | Output is correct |
57 | Correct | 2 ms | 768 KB | Output is correct |
58 | Correct | 2 ms | 768 KB | Output is correct |
59 | Correct | 273 ms | 4344 KB | Output is correct |
60 | Correct | 253 ms | 4472 KB | Output is correct |
61 | Correct | 249 ms | 4416 KB | Output is correct |
62 | Correct | 279 ms | 4332 KB | Output is correct |
63 | Correct | 260 ms | 4348 KB | Output is correct |
64 | Correct | 582 ms | 4424 KB | Output is correct |
65 | Correct | 588 ms | 4344 KB | Output is correct |
66 | Correct | 592 ms | 4496 KB | Output is correct |
67 | Correct | 589 ms | 4472 KB | Output is correct |
68 | Correct | 587 ms | 4344 KB | Output is correct |
69 | Correct | 226 ms | 4392 KB | Output is correct |
70 | Correct | 222 ms | 4344 KB | Output is correct |
71 | Correct | 234 ms | 4284 KB | Output is correct |
72 | Correct | 236 ms | 4344 KB | Output is correct |
73 | Correct | 250 ms | 4344 KB | Output is correct |
74 | Correct | 53 ms | 1144 KB | Output is correct |
75 | Correct | 51 ms | 1144 KB | Output is correct |
76 | Correct | 53 ms | 1144 KB | Output is correct |
77 | Correct | 53 ms | 1068 KB | Output is correct |
78 | Correct | 53 ms | 1144 KB | Output is correct |