# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
255088 |
2020-07-31T09:06:46 Z |
maximath_1 |
Boat (APIO16_boat) |
C++11 |
|
448 ms |
8440 KB |
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
int n;
ll st[1005], ed[1005], len[1005];
ll inv[1005], dp[1005][1005];
vector<ll> cc;
ll add(ll a, ll b){
ll res = a + b;
if(res >= mod) res -= mod;
return res;
}
ll mul(ll a, ll b){
return (a * 1ll * b) % mod;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> st[i] >> ed[i];
ed[i] ++;
}
inv[1] = 1ll;
for(int i = 2; i <= n; i ++)
inv[i] = mul(mod / i, mod - inv[mod % i]);
for(int i = 1; i <= n; i ++){
cc.push_back(st[i]);cc.push_back(ed[i]);
}
sort(cc.begin(), cc.end());
cc.erase(unique(cc.begin(), cc.end()), cc.end());
for(int i = 1; i <= n; i ++){
st[i] = upper_bound(cc.begin(), cc.end(), st[i]) - cc.begin();
ed[i] = upper_bound(cc.begin(), cc.end(), ed[i]) - cc.begin();
}
int sz = cc.size() - 1;
for(int i = 1; i <= sz; i ++)
len[i] = cc[i] - cc[i - 1];
dp[0][0] = 1ll;
for(int i = 1; i <= sz; i ++){
dp[i][0] = 1ll;
for(int j = 1; j <= n; j ++){
ll choose = len[i]; int cnt = 1;
dp[i][j] = dp[i - 1][j];
if(i < st[j] || i >= ed[j]) continue;
for(int k = j - 1; k >= 0; k --){
dp[i][j] = add(dp[i][j], mul(dp[i - 1][k], choose));
if(st[k] <= i && i < ed[k]){
choose = mul(choose, mul(add(cnt, len[i]), inv[cnt + 1]));
cnt ++;
}
}
}
}
ll ans = 0ll;
for(int i = 1; i <= n; i ++)
ans = add(ans, dp[sz][i]);
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8192 KB |
Output is correct |
2 |
Correct |
7 ms |
8192 KB |
Output is correct |
3 |
Correct |
6 ms |
8192 KB |
Output is correct |
4 |
Correct |
7 ms |
8192 KB |
Output is correct |
5 |
Correct |
6 ms |
8192 KB |
Output is correct |
6 |
Correct |
5 ms |
8192 KB |
Output is correct |
7 |
Correct |
5 ms |
8192 KB |
Output is correct |
8 |
Correct |
6 ms |
8192 KB |
Output is correct |
9 |
Correct |
5 ms |
8320 KB |
Output is correct |
10 |
Correct |
5 ms |
8192 KB |
Output is correct |
11 |
Correct |
5 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
5 ms |
8192 KB |
Output is correct |
14 |
Correct |
5 ms |
8192 KB |
Output is correct |
15 |
Correct |
6 ms |
8192 KB |
Output is correct |
16 |
Correct |
2 ms |
1792 KB |
Output is correct |
17 |
Correct |
2 ms |
1920 KB |
Output is correct |
18 |
Correct |
3 ms |
1792 KB |
Output is correct |
19 |
Correct |
3 ms |
1920 KB |
Output is correct |
20 |
Correct |
3 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8192 KB |
Output is correct |
2 |
Correct |
7 ms |
8192 KB |
Output is correct |
3 |
Correct |
6 ms |
8192 KB |
Output is correct |
4 |
Correct |
7 ms |
8192 KB |
Output is correct |
5 |
Correct |
6 ms |
8192 KB |
Output is correct |
6 |
Correct |
5 ms |
8192 KB |
Output is correct |
7 |
Correct |
5 ms |
8192 KB |
Output is correct |
8 |
Correct |
6 ms |
8192 KB |
Output is correct |
9 |
Correct |
5 ms |
8320 KB |
Output is correct |
10 |
Correct |
5 ms |
8192 KB |
Output is correct |
11 |
Correct |
5 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
5 ms |
8192 KB |
Output is correct |
14 |
Correct |
5 ms |
8192 KB |
Output is correct |
15 |
Correct |
6 ms |
8192 KB |
Output is correct |
16 |
Correct |
2 ms |
1792 KB |
Output is correct |
17 |
Correct |
2 ms |
1920 KB |
Output is correct |
18 |
Correct |
3 ms |
1792 KB |
Output is correct |
19 |
Correct |
3 ms |
1920 KB |
Output is correct |
20 |
Correct |
3 ms |
1792 KB |
Output is correct |
21 |
Correct |
250 ms |
7516 KB |
Output is correct |
22 |
Correct |
231 ms |
7676 KB |
Output is correct |
23 |
Correct |
216 ms |
7544 KB |
Output is correct |
24 |
Correct |
246 ms |
7416 KB |
Output is correct |
25 |
Correct |
243 ms |
7544 KB |
Output is correct |
26 |
Correct |
390 ms |
7288 KB |
Output is correct |
27 |
Correct |
382 ms |
7416 KB |
Output is correct |
28 |
Correct |
387 ms |
7288 KB |
Output is correct |
29 |
Correct |
366 ms |
7288 KB |
Output is correct |
30 |
Correct |
6 ms |
8192 KB |
Output is correct |
31 |
Correct |
6 ms |
8192 KB |
Output is correct |
32 |
Correct |
8 ms |
8192 KB |
Output is correct |
33 |
Correct |
8 ms |
8320 KB |
Output is correct |
34 |
Correct |
6 ms |
8192 KB |
Output is correct |
35 |
Correct |
8 ms |
8192 KB |
Output is correct |
36 |
Correct |
10 ms |
8192 KB |
Output is correct |
37 |
Correct |
8 ms |
8192 KB |
Output is correct |
38 |
Correct |
8 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1280 KB |
Output is correct |
2 |
Correct |
3 ms |
1280 KB |
Output is correct |
3 |
Correct |
3 ms |
1280 KB |
Output is correct |
4 |
Correct |
3 ms |
1280 KB |
Output is correct |
5 |
Correct |
3 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
7 |
Correct |
4 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1280 KB |
Output is correct |
9 |
Correct |
5 ms |
1280 KB |
Output is correct |
10 |
Correct |
5 ms |
1280 KB |
Output is correct |
11 |
Correct |
3 ms |
1280 KB |
Output is correct |
12 |
Correct |
3 ms |
1280 KB |
Output is correct |
13 |
Correct |
3 ms |
1280 KB |
Output is correct |
14 |
Correct |
3 ms |
1280 KB |
Output is correct |
15 |
Correct |
3 ms |
1280 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
896 KB |
Output is correct |
20 |
Correct |
2 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8192 KB |
Output is correct |
2 |
Correct |
7 ms |
8192 KB |
Output is correct |
3 |
Correct |
6 ms |
8192 KB |
Output is correct |
4 |
Correct |
7 ms |
8192 KB |
Output is correct |
5 |
Correct |
6 ms |
8192 KB |
Output is correct |
6 |
Correct |
5 ms |
8192 KB |
Output is correct |
7 |
Correct |
5 ms |
8192 KB |
Output is correct |
8 |
Correct |
6 ms |
8192 KB |
Output is correct |
9 |
Correct |
5 ms |
8320 KB |
Output is correct |
10 |
Correct |
5 ms |
8192 KB |
Output is correct |
11 |
Correct |
5 ms |
8192 KB |
Output is correct |
12 |
Correct |
8 ms |
8192 KB |
Output is correct |
13 |
Correct |
5 ms |
8192 KB |
Output is correct |
14 |
Correct |
5 ms |
8192 KB |
Output is correct |
15 |
Correct |
6 ms |
8192 KB |
Output is correct |
16 |
Correct |
2 ms |
1792 KB |
Output is correct |
17 |
Correct |
2 ms |
1920 KB |
Output is correct |
18 |
Correct |
3 ms |
1792 KB |
Output is correct |
19 |
Correct |
3 ms |
1920 KB |
Output is correct |
20 |
Correct |
3 ms |
1792 KB |
Output is correct |
21 |
Correct |
250 ms |
7516 KB |
Output is correct |
22 |
Correct |
231 ms |
7676 KB |
Output is correct |
23 |
Correct |
216 ms |
7544 KB |
Output is correct |
24 |
Correct |
246 ms |
7416 KB |
Output is correct |
25 |
Correct |
243 ms |
7544 KB |
Output is correct |
26 |
Correct |
390 ms |
7288 KB |
Output is correct |
27 |
Correct |
382 ms |
7416 KB |
Output is correct |
28 |
Correct |
387 ms |
7288 KB |
Output is correct |
29 |
Correct |
366 ms |
7288 KB |
Output is correct |
30 |
Correct |
6 ms |
8192 KB |
Output is correct |
31 |
Correct |
6 ms |
8192 KB |
Output is correct |
32 |
Correct |
8 ms |
8192 KB |
Output is correct |
33 |
Correct |
8 ms |
8320 KB |
Output is correct |
34 |
Correct |
6 ms |
8192 KB |
Output is correct |
35 |
Correct |
8 ms |
8192 KB |
Output is correct |
36 |
Correct |
10 ms |
8192 KB |
Output is correct |
37 |
Correct |
8 ms |
8192 KB |
Output is correct |
38 |
Correct |
8 ms |
8192 KB |
Output is correct |
39 |
Correct |
3 ms |
1280 KB |
Output is correct |
40 |
Correct |
3 ms |
1280 KB |
Output is correct |
41 |
Correct |
3 ms |
1280 KB |
Output is correct |
42 |
Correct |
3 ms |
1280 KB |
Output is correct |
43 |
Correct |
3 ms |
1280 KB |
Output is correct |
44 |
Correct |
5 ms |
1280 KB |
Output is correct |
45 |
Correct |
4 ms |
1280 KB |
Output is correct |
46 |
Correct |
5 ms |
1280 KB |
Output is correct |
47 |
Correct |
5 ms |
1280 KB |
Output is correct |
48 |
Correct |
5 ms |
1280 KB |
Output is correct |
49 |
Correct |
3 ms |
1280 KB |
Output is correct |
50 |
Correct |
3 ms |
1280 KB |
Output is correct |
51 |
Correct |
3 ms |
1280 KB |
Output is correct |
52 |
Correct |
3 ms |
1280 KB |
Output is correct |
53 |
Correct |
3 ms |
1280 KB |
Output is correct |
54 |
Correct |
2 ms |
896 KB |
Output is correct |
55 |
Correct |
2 ms |
896 KB |
Output is correct |
56 |
Correct |
2 ms |
896 KB |
Output is correct |
57 |
Correct |
2 ms |
896 KB |
Output is correct |
58 |
Correct |
2 ms |
896 KB |
Output is correct |
59 |
Correct |
264 ms |
8176 KB |
Output is correct |
60 |
Correct |
249 ms |
8184 KB |
Output is correct |
61 |
Correct |
237 ms |
8184 KB |
Output is correct |
62 |
Correct |
272 ms |
8184 KB |
Output is correct |
63 |
Correct |
258 ms |
8312 KB |
Output is correct |
64 |
Correct |
443 ms |
8184 KB |
Output is correct |
65 |
Correct |
438 ms |
8184 KB |
Output is correct |
66 |
Correct |
448 ms |
8184 KB |
Output is correct |
67 |
Correct |
436 ms |
8440 KB |
Output is correct |
68 |
Correct |
434 ms |
8312 KB |
Output is correct |
69 |
Correct |
208 ms |
8312 KB |
Output is correct |
70 |
Correct |
205 ms |
8292 KB |
Output is correct |
71 |
Correct |
204 ms |
8312 KB |
Output is correct |
72 |
Correct |
215 ms |
8184 KB |
Output is correct |
73 |
Correct |
216 ms |
8312 KB |
Output is correct |
74 |
Correct |
51 ms |
1784 KB |
Output is correct |
75 |
Correct |
48 ms |
1784 KB |
Output is correct |
76 |
Correct |
55 ms |
1784 KB |
Output is correct |
77 |
Correct |
51 ms |
1784 KB |
Output is correct |
78 |
Correct |
53 ms |
1784 KB |
Output is correct |