# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
551919 |
2022-04-21T22:13:31 Z |
nafis_shifat |
Boat (APIO16_boat) |
C++17 |
|
1454 ms |
36028 KB |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1500+5;
const int inf=1e9;
const ll mod = 1e9 + 7;
ll bigmod(ll a, ll b) {
if(b == 0) return 1;
int mid = b / 2;
ll res = bigmod(a, mid);
res = res * res % mod;
if(b % 2 == 1) return a * res % mod;
return res;
}
ll last[mxn][mxn] = {};
ll dp[mxn][mxn] = {};
ll sum[mxn][mxn] = {};
ll fact[mxn], inv[mxn];
ll pre[mxn][mxn] = {};
ll ncr(ll n, ll r) {
if(r > n) return 0;
ll res = fact[n];
res = res * inv[r] % mod;
res = res * inv[n - r] % mod;
return res;
}
int main() {
fact[0] = 1;
inv[0] = 1;
for(int i = 1; i < mxn; i++) {
fact[i] = fact[i - 1] * i % mod;
inv[i] = bigmod(fact[i], mod - 2) % mod;
}
int n;
cin >> n;
int a[n + 1], b[n + 1];
int l[n + 1] = {}, r[n + 1] = {};
vector<int> v;
v.push_back(0);
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
v.push_back(a[i]);
v.push_back(a[i] - 1);
v.push_back(b[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int len[v.size() + 2];
for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1];
for(int i = 1; i < v.size(); i++) {
for(int j = 1; j <= n; j++) {
ll mul = 1;
ll tot = 0;
ll mul2 = 1;
for(int k = 1; k <= min(j + 1, len[i]); k++) {
mul = mul * (len[i] - k + 1) % mod;
ll v1 = mul * inv[k] % mod;
ll v2 = mul2 * inv[k - 1] % mod;
// cout<<i<<" "<<j<<" "<<k<<endl;
// assert(ncr(j - 1, k - 1) == v2);
pre[i][j] += v2 * v1 % mod;
mul2 = mul2 * (j - k) % mod;
}
pre[i][j] %= mod;
}
}
for(int i = 1; i <= n; i++) {
l[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
r[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
}
dp[0][0] = 1;
for(int i = 0; i < v.size(); i++) sum[i][0] = 1;
ll ans = 0;
for(int p = 1; p <= n; p++) {
for(int i = l[p]; i <= r[p]; i++) {
ll tot = len[i];
ll found = 1;
for(int j = p - 1; j >= 0; j--) {
dp[i][j] = sum[i - 1][j] * pre[i][found] % mod;
sum[i][p] = (sum[i][p] + dp[i][j]) % mod;
if(l[j] <= i && i <= r[j]) found++;
}
}
for(int i = l[p]; i < v.size(); i++) sum[i][p] = (sum[i][p] + sum[i - 1][p]) % mod;
ans += sum[v.size() - 1][p];
}
cout<<ans % mod<<endl;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1];
| ~~^~~~~~~~~~
boat.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
boat.cpp:66:7: warning: unused variable 'tot' [-Wunused-variable]
66 | ll tot = 0;
| ^~~
boat.cpp:98:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(int i = 0; i < v.size(); i++) sum[i][0] = 1;
| ~~^~~~~~~~~~
boat.cpp:104:10: warning: unused variable 'tot' [-Wunused-variable]
104 | ll tot = len[i];
| ^~~
boat.cpp:121:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
121 | for(int i = l[p]; i < v.size(); i++) sum[i][p] = (sum[i][p] + sum[i - 1][p]) % mod;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
522 ms |
19176 KB |
Output is correct |
2 |
Correct |
516 ms |
19160 KB |
Output is correct |
3 |
Correct |
526 ms |
19156 KB |
Output is correct |
4 |
Correct |
515 ms |
19168 KB |
Output is correct |
5 |
Correct |
510 ms |
19148 KB |
Output is correct |
6 |
Correct |
530 ms |
18080 KB |
Output is correct |
7 |
Correct |
528 ms |
17800 KB |
Output is correct |
8 |
Correct |
518 ms |
18372 KB |
Output is correct |
9 |
Correct |
518 ms |
18344 KB |
Output is correct |
10 |
Correct |
520 ms |
18488 KB |
Output is correct |
11 |
Correct |
520 ms |
18284 KB |
Output is correct |
12 |
Correct |
523 ms |
19220 KB |
Output is correct |
13 |
Correct |
519 ms |
18476 KB |
Output is correct |
14 |
Correct |
522 ms |
18004 KB |
Output is correct |
15 |
Correct |
524 ms |
18632 KB |
Output is correct |
16 |
Correct |
95 ms |
3800 KB |
Output is correct |
17 |
Correct |
102 ms |
3912 KB |
Output is correct |
18 |
Correct |
95 ms |
3756 KB |
Output is correct |
19 |
Correct |
103 ms |
4008 KB |
Output is correct |
20 |
Correct |
98 ms |
3880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
522 ms |
19176 KB |
Output is correct |
2 |
Correct |
516 ms |
19160 KB |
Output is correct |
3 |
Correct |
526 ms |
19156 KB |
Output is correct |
4 |
Correct |
515 ms |
19168 KB |
Output is correct |
5 |
Correct |
510 ms |
19148 KB |
Output is correct |
6 |
Correct |
530 ms |
18080 KB |
Output is correct |
7 |
Correct |
528 ms |
17800 KB |
Output is correct |
8 |
Correct |
518 ms |
18372 KB |
Output is correct |
9 |
Correct |
518 ms |
18344 KB |
Output is correct |
10 |
Correct |
520 ms |
18488 KB |
Output is correct |
11 |
Correct |
520 ms |
18284 KB |
Output is correct |
12 |
Correct |
523 ms |
19220 KB |
Output is correct |
13 |
Correct |
519 ms |
18476 KB |
Output is correct |
14 |
Correct |
522 ms |
18004 KB |
Output is correct |
15 |
Correct |
524 ms |
18632 KB |
Output is correct |
16 |
Correct |
95 ms |
3800 KB |
Output is correct |
17 |
Correct |
102 ms |
3912 KB |
Output is correct |
18 |
Correct |
95 ms |
3756 KB |
Output is correct |
19 |
Correct |
103 ms |
4008 KB |
Output is correct |
20 |
Correct |
98 ms |
3880 KB |
Output is correct |
21 |
Correct |
335 ms |
31304 KB |
Output is correct |
22 |
Correct |
335 ms |
31592 KB |
Output is correct |
23 |
Correct |
302 ms |
30900 KB |
Output is correct |
24 |
Correct |
333 ms |
31300 KB |
Output is correct |
25 |
Correct |
319 ms |
30668 KB |
Output is correct |
26 |
Correct |
376 ms |
27684 KB |
Output is correct |
27 |
Correct |
368 ms |
28624 KB |
Output is correct |
28 |
Correct |
381 ms |
28872 KB |
Output is correct |
29 |
Correct |
371 ms |
28732 KB |
Output is correct |
30 |
Correct |
499 ms |
31272 KB |
Output is correct |
31 |
Correct |
518 ms |
30516 KB |
Output is correct |
32 |
Correct |
520 ms |
30888 KB |
Output is correct |
33 |
Correct |
509 ms |
30824 KB |
Output is correct |
34 |
Correct |
505 ms |
30564 KB |
Output is correct |
35 |
Correct |
506 ms |
22400 KB |
Output is correct |
36 |
Correct |
488 ms |
22316 KB |
Output is correct |
37 |
Correct |
509 ms |
22476 KB |
Output is correct |
38 |
Correct |
493 ms |
22436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
4640 KB |
Output is correct |
2 |
Correct |
14 ms |
4568 KB |
Output is correct |
3 |
Correct |
13 ms |
4596 KB |
Output is correct |
4 |
Correct |
14 ms |
4580 KB |
Output is correct |
5 |
Correct |
15 ms |
4564 KB |
Output is correct |
6 |
Correct |
14 ms |
4488 KB |
Output is correct |
7 |
Correct |
15 ms |
4552 KB |
Output is correct |
8 |
Correct |
17 ms |
4520 KB |
Output is correct |
9 |
Correct |
15 ms |
4512 KB |
Output is correct |
10 |
Correct |
14 ms |
4568 KB |
Output is correct |
11 |
Correct |
13 ms |
4572 KB |
Output is correct |
12 |
Correct |
13 ms |
4564 KB |
Output is correct |
13 |
Correct |
13 ms |
4436 KB |
Output is correct |
14 |
Correct |
14 ms |
4564 KB |
Output is correct |
15 |
Correct |
14 ms |
4564 KB |
Output is correct |
16 |
Correct |
7 ms |
2388 KB |
Output is correct |
17 |
Correct |
6 ms |
2388 KB |
Output is correct |
18 |
Correct |
8 ms |
2396 KB |
Output is correct |
19 |
Correct |
7 ms |
2348 KB |
Output is correct |
20 |
Correct |
7 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
522 ms |
19176 KB |
Output is correct |
2 |
Correct |
516 ms |
19160 KB |
Output is correct |
3 |
Correct |
526 ms |
19156 KB |
Output is correct |
4 |
Correct |
515 ms |
19168 KB |
Output is correct |
5 |
Correct |
510 ms |
19148 KB |
Output is correct |
6 |
Correct |
530 ms |
18080 KB |
Output is correct |
7 |
Correct |
528 ms |
17800 KB |
Output is correct |
8 |
Correct |
518 ms |
18372 KB |
Output is correct |
9 |
Correct |
518 ms |
18344 KB |
Output is correct |
10 |
Correct |
520 ms |
18488 KB |
Output is correct |
11 |
Correct |
520 ms |
18284 KB |
Output is correct |
12 |
Correct |
523 ms |
19220 KB |
Output is correct |
13 |
Correct |
519 ms |
18476 KB |
Output is correct |
14 |
Correct |
522 ms |
18004 KB |
Output is correct |
15 |
Correct |
524 ms |
18632 KB |
Output is correct |
16 |
Correct |
95 ms |
3800 KB |
Output is correct |
17 |
Correct |
102 ms |
3912 KB |
Output is correct |
18 |
Correct |
95 ms |
3756 KB |
Output is correct |
19 |
Correct |
103 ms |
4008 KB |
Output is correct |
20 |
Correct |
98 ms |
3880 KB |
Output is correct |
21 |
Correct |
335 ms |
31304 KB |
Output is correct |
22 |
Correct |
335 ms |
31592 KB |
Output is correct |
23 |
Correct |
302 ms |
30900 KB |
Output is correct |
24 |
Correct |
333 ms |
31300 KB |
Output is correct |
25 |
Correct |
319 ms |
30668 KB |
Output is correct |
26 |
Correct |
376 ms |
27684 KB |
Output is correct |
27 |
Correct |
368 ms |
28624 KB |
Output is correct |
28 |
Correct |
381 ms |
28872 KB |
Output is correct |
29 |
Correct |
371 ms |
28732 KB |
Output is correct |
30 |
Correct |
499 ms |
31272 KB |
Output is correct |
31 |
Correct |
518 ms |
30516 KB |
Output is correct |
32 |
Correct |
520 ms |
30888 KB |
Output is correct |
33 |
Correct |
509 ms |
30824 KB |
Output is correct |
34 |
Correct |
505 ms |
30564 KB |
Output is correct |
35 |
Correct |
506 ms |
22400 KB |
Output is correct |
36 |
Correct |
488 ms |
22316 KB |
Output is correct |
37 |
Correct |
509 ms |
22476 KB |
Output is correct |
38 |
Correct |
493 ms |
22436 KB |
Output is correct |
39 |
Correct |
14 ms |
4640 KB |
Output is correct |
40 |
Correct |
14 ms |
4568 KB |
Output is correct |
41 |
Correct |
13 ms |
4596 KB |
Output is correct |
42 |
Correct |
14 ms |
4580 KB |
Output is correct |
43 |
Correct |
15 ms |
4564 KB |
Output is correct |
44 |
Correct |
14 ms |
4488 KB |
Output is correct |
45 |
Correct |
15 ms |
4552 KB |
Output is correct |
46 |
Correct |
17 ms |
4520 KB |
Output is correct |
47 |
Correct |
15 ms |
4512 KB |
Output is correct |
48 |
Correct |
14 ms |
4568 KB |
Output is correct |
49 |
Correct |
13 ms |
4572 KB |
Output is correct |
50 |
Correct |
13 ms |
4564 KB |
Output is correct |
51 |
Correct |
13 ms |
4436 KB |
Output is correct |
52 |
Correct |
14 ms |
4564 KB |
Output is correct |
53 |
Correct |
14 ms |
4564 KB |
Output is correct |
54 |
Correct |
7 ms |
2388 KB |
Output is correct |
55 |
Correct |
6 ms |
2388 KB |
Output is correct |
56 |
Correct |
8 ms |
2396 KB |
Output is correct |
57 |
Correct |
7 ms |
2348 KB |
Output is correct |
58 |
Correct |
7 ms |
2388 KB |
Output is correct |
59 |
Correct |
1359 ms |
36028 KB |
Output is correct |
60 |
Correct |
1336 ms |
35788 KB |
Output is correct |
61 |
Correct |
1340 ms |
35872 KB |
Output is correct |
62 |
Correct |
1373 ms |
35728 KB |
Output is correct |
63 |
Correct |
1351 ms |
35900 KB |
Output is correct |
64 |
Correct |
1454 ms |
34528 KB |
Output is correct |
65 |
Correct |
1434 ms |
33612 KB |
Output is correct |
66 |
Correct |
1441 ms |
34788 KB |
Output is correct |
67 |
Correct |
1432 ms |
34172 KB |
Output is correct |
68 |
Correct |
1423 ms |
35244 KB |
Output is correct |
69 |
Correct |
1249 ms |
33840 KB |
Output is correct |
70 |
Correct |
1248 ms |
34664 KB |
Output is correct |
71 |
Correct |
1231 ms |
33620 KB |
Output is correct |
72 |
Correct |
1247 ms |
34020 KB |
Output is correct |
73 |
Correct |
1253 ms |
34236 KB |
Output is correct |
74 |
Correct |
148 ms |
4812 KB |
Output is correct |
75 |
Correct |
147 ms |
4904 KB |
Output is correct |
76 |
Correct |
151 ms |
4964 KB |
Output is correct |
77 |
Correct |
150 ms |
4856 KB |
Output is correct |
78 |
Correct |
148 ms |
4804 KB |
Output is correct |