# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
278536 | 2020-08-21T14:01:17 Z | BeanZ | Boat (APIO16_boat) | C++14 | 1434 ms | 4604 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]; ll 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 | 5 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 | 5 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 | 4 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 | 2 ms | 1152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 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 | 5 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 | 4 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 | 2 ms | 1152 KB | Output is correct |
21 | Correct | 509 ms | 4008 KB | Output is correct |
22 | Correct | 486 ms | 4088 KB | Output is correct |
23 | Correct | 445 ms | 3960 KB | Output is correct |
24 | Correct | 490 ms | 3996 KB | Output is correct |
25 | Correct | 499 ms | 3960 KB | Output is correct |
26 | Correct | 919 ms | 3904 KB | Output is correct |
27 | Correct | 953 ms | 4016 KB | Output is correct |
28 | Correct | 935 ms | 3892 KB | Output is correct |
29 | Correct | 926 ms | 4088 KB | Output is correct |
30 | Correct | 6 ms | 4352 KB | Output is correct |
31 | Correct | 6 ms | 4352 KB | Output is correct |
32 | Correct | 6 ms | 4352 KB | Output is correct |
33 | Correct | 6 ms | 4352 KB | Output is correct |
34 | Correct | 6 ms | 4328 KB | Output is correct |
35 | Correct | 7 ms | 4352 KB | Output is correct |
36 | Correct | 7 ms | 4352 KB | Output is correct |
37 | Correct | 6 ms | 4352 KB | Output is correct |
38 | Correct | 7 ms | 4352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 1152 KB | Output is correct |
2 | Correct | 5 ms | 1152 KB | Output is correct |
3 | Correct | 6 ms | 1152 KB | Output is correct |
4 | Correct | 6 ms | 1152 KB | Output is correct |
5 | Correct | 7 ms | 1184 KB | Output is correct |
6 | Correct | 13 ms | 1152 KB | Output is correct |
7 | Correct | 12 ms | 1152 KB | Output is correct |
8 | Correct | 13 ms | 1184 KB | Output is correct |
9 | Correct | 12 ms | 1152 KB | Output is correct |
10 | Correct | 13 ms | 1152 KB | Output is correct |
11 | Correct | 8 ms | 1184 KB | Output is correct |
12 | Correct | 6 ms | 1152 KB | Output is correct |
13 | Correct | 6 ms | 1152 KB | Output is correct |
14 | Correct | 6 ms | 1152 KB | Output is correct |
15 | Correct | 7 ms | 1152 KB | Output is correct |
16 | Correct | 4 ms | 896 KB | Output is correct |
17 | Correct | 4 ms | 768 KB | Output is correct |
18 | Correct | 4 ms | 768 KB | Output is correct |
19 | Correct | 4 ms | 768 KB | Output is correct |
20 | Correct | 4 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 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 | 5 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 | 4 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 | 2 ms | 1152 KB | Output is correct |
21 | Correct | 509 ms | 4008 KB | Output is correct |
22 | Correct | 486 ms | 4088 KB | Output is correct |
23 | Correct | 445 ms | 3960 KB | Output is correct |
24 | Correct | 490 ms | 3996 KB | Output is correct |
25 | Correct | 499 ms | 3960 KB | Output is correct |
26 | Correct | 919 ms | 3904 KB | Output is correct |
27 | Correct | 953 ms | 4016 KB | Output is correct |
28 | Correct | 935 ms | 3892 KB | Output is correct |
29 | Correct | 926 ms | 4088 KB | Output is correct |
30 | Correct | 6 ms | 4352 KB | Output is correct |
31 | Correct | 6 ms | 4352 KB | Output is correct |
32 | Correct | 6 ms | 4352 KB | Output is correct |
33 | Correct | 6 ms | 4352 KB | Output is correct |
34 | Correct | 6 ms | 4328 KB | Output is correct |
35 | Correct | 7 ms | 4352 KB | Output is correct |
36 | Correct | 7 ms | 4352 KB | Output is correct |
37 | Correct | 6 ms | 4352 KB | Output is correct |
38 | Correct | 7 ms | 4352 KB | Output is correct |
39 | Correct | 7 ms | 1152 KB | Output is correct |
40 | Correct | 5 ms | 1152 KB | Output is correct |
41 | Correct | 6 ms | 1152 KB | Output is correct |
42 | Correct | 6 ms | 1152 KB | Output is correct |
43 | Correct | 7 ms | 1184 KB | Output is correct |
44 | Correct | 13 ms | 1152 KB | Output is correct |
45 | Correct | 12 ms | 1152 KB | Output is correct |
46 | Correct | 13 ms | 1184 KB | Output is correct |
47 | Correct | 12 ms | 1152 KB | Output is correct |
48 | Correct | 13 ms | 1152 KB | Output is correct |
49 | Correct | 8 ms | 1184 KB | Output is correct |
50 | Correct | 6 ms | 1152 KB | Output is correct |
51 | Correct | 6 ms | 1152 KB | Output is correct |
52 | Correct | 6 ms | 1152 KB | Output is correct |
53 | Correct | 7 ms | 1152 KB | Output is correct |
54 | Correct | 4 ms | 896 KB | Output is correct |
55 | Correct | 4 ms | 768 KB | Output is correct |
56 | Correct | 4 ms | 768 KB | Output is correct |
57 | Correct | 4 ms | 768 KB | Output is correct |
58 | Correct | 4 ms | 768 KB | Output is correct |
59 | Correct | 710 ms | 4472 KB | Output is correct |
60 | Correct | 659 ms | 4344 KB | Output is correct |
61 | Correct | 619 ms | 4604 KB | Output is correct |
62 | Correct | 726 ms | 4344 KB | Output is correct |
63 | Correct | 693 ms | 4472 KB | Output is correct |
64 | Correct | 1433 ms | 4492 KB | Output is correct |
65 | Correct | 1429 ms | 4472 KB | Output is correct |
66 | Correct | 1426 ms | 4452 KB | Output is correct |
67 | Correct | 1434 ms | 4600 KB | Output is correct |
68 | Correct | 1424 ms | 4600 KB | Output is correct |
69 | Correct | 620 ms | 4344 KB | Output is correct |
70 | Correct | 615 ms | 4472 KB | Output is correct |
71 | Correct | 613 ms | 4344 KB | Output is correct |
72 | Correct | 647 ms | 4388 KB | Output is correct |
73 | Correct | 658 ms | 4440 KB | Output is correct |
74 | Correct | 114 ms | 1144 KB | Output is correct |
75 | Correct | 108 ms | 1180 KB | Output is correct |
76 | Correct | 115 ms | 1052 KB | Output is correct |
77 | Correct | 112 ms | 1144 KB | Output is correct |
78 | Correct | 119 ms | 1156 KB | Output is correct |