# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
981183 |
2024-05-13T01:29:50 Z |
hmm789 |
Boat (APIO16_boat) |
C++14 |
|
479 ms |
8528 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
int pwr(int x, int n) {
if(n == 0) return 1;
if(n == 1) return x;
int h = pwr(x, n/2);
if(n%2 == 0) return h*h%MOD;
else return h*h%MOD*x%MOD;
}
int inv2(int x) {
return pwr(x, MOD-2);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
// regions [l, r)
vector<pair<int, int>> v;
vector<int> len;
int a[n+1], b[n+1], inv[n+1], ans = 0;
for(int i = 1; i <= n; i++) inv[i] = inv2(i);
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
v.push_back({a[i], i});
v.push_back({b[i]+1, i+n});
}
v.push_back({0, 0});
sort(v.begin(), v.end());
int cnt = 0;
for(int i = 0; i < v.size(); i++) {
if(v[i].second <= n) a[v[i].second] = cnt;
else b[v[i].second-n] = cnt-1;
if(i != v.size()-1 && v[i].first != v[i+1].first) {
len.push_back(v[i+1].first-v[i].first);
cnt++;
}
}
int dp[n+1][cnt], pref[n+1][cnt];
memset(dp, 0, sizeof(dp));
memset(pref, 0, sizeof(pref));
dp[0][0] = 1;
for(int i = 0; i < cnt; i++) pref[0][i] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j < cnt; j++) {
if(j >= a[i] && j <= b[i]) {
int c = len[j], cur = 1;
for(int k = i-1; k >= 0; k--) {
dp[i][j] += pref[k][j-1] * c % MOD;
dp[i][j] %= MOD;
if(j >= a[k] && j <= b[k]) {
cur++;
c = c*(len[j]+cur-1)%MOD * inv[cur]%MOD;
}
}
}
pref[i][j] = (pref[i][j-1]+dp[i][j]) % MOD;
ans = (ans+dp[i][j]) % MOD;
}
}
cout << ans;
}
Compilation message
boat.cpp: In function 'int32_t main()':
boat.cpp:36:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
boat.cpp:39:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(i != v.size()-1 && v[i].first != v[i+1].first) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8284 KB |
Output is correct |
2 |
Correct |
8 ms |
8284 KB |
Output is correct |
3 |
Correct |
8 ms |
8284 KB |
Output is correct |
4 |
Correct |
8 ms |
8440 KB |
Output is correct |
5 |
Correct |
9 ms |
8280 KB |
Output is correct |
6 |
Correct |
8 ms |
8268 KB |
Output is correct |
7 |
Correct |
9 ms |
8284 KB |
Output is correct |
8 |
Correct |
8 ms |
8284 KB |
Output is correct |
9 |
Correct |
8 ms |
8284 KB |
Output is correct |
10 |
Correct |
10 ms |
8284 KB |
Output is correct |
11 |
Correct |
9 ms |
8284 KB |
Output is correct |
12 |
Correct |
8 ms |
8284 KB |
Output is correct |
13 |
Correct |
9 ms |
8284 KB |
Output is correct |
14 |
Correct |
8 ms |
8284 KB |
Output is correct |
15 |
Correct |
9 ms |
8284 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1884 KB |
Output is correct |
19 |
Correct |
3 ms |
1796 KB |
Output is correct |
20 |
Correct |
2 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8284 KB |
Output is correct |
2 |
Correct |
8 ms |
8284 KB |
Output is correct |
3 |
Correct |
8 ms |
8284 KB |
Output is correct |
4 |
Correct |
8 ms |
8440 KB |
Output is correct |
5 |
Correct |
9 ms |
8280 KB |
Output is correct |
6 |
Correct |
8 ms |
8268 KB |
Output is correct |
7 |
Correct |
9 ms |
8284 KB |
Output is correct |
8 |
Correct |
8 ms |
8284 KB |
Output is correct |
9 |
Correct |
8 ms |
8284 KB |
Output is correct |
10 |
Correct |
10 ms |
8284 KB |
Output is correct |
11 |
Correct |
9 ms |
8284 KB |
Output is correct |
12 |
Correct |
8 ms |
8284 KB |
Output is correct |
13 |
Correct |
9 ms |
8284 KB |
Output is correct |
14 |
Correct |
8 ms |
8284 KB |
Output is correct |
15 |
Correct |
9 ms |
8284 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1884 KB |
Output is correct |
19 |
Correct |
3 ms |
1796 KB |
Output is correct |
20 |
Correct |
2 ms |
1872 KB |
Output is correct |
21 |
Correct |
225 ms |
7636 KB |
Output is correct |
22 |
Correct |
218 ms |
7764 KB |
Output is correct |
23 |
Correct |
196 ms |
7516 KB |
Output is correct |
24 |
Correct |
221 ms |
7516 KB |
Output is correct |
25 |
Correct |
215 ms |
7512 KB |
Output is correct |
26 |
Correct |
415 ms |
7384 KB |
Output is correct |
27 |
Correct |
427 ms |
7512 KB |
Output is correct |
28 |
Correct |
418 ms |
7392 KB |
Output is correct |
29 |
Correct |
418 ms |
7608 KB |
Output is correct |
30 |
Correct |
9 ms |
8284 KB |
Output is correct |
31 |
Correct |
9 ms |
8284 KB |
Output is correct |
32 |
Correct |
9 ms |
8284 KB |
Output is correct |
33 |
Correct |
9 ms |
8284 KB |
Output is correct |
34 |
Correct |
10 ms |
8436 KB |
Output is correct |
35 |
Correct |
9 ms |
8140 KB |
Output is correct |
36 |
Correct |
9 ms |
8336 KB |
Output is correct |
37 |
Correct |
10 ms |
8284 KB |
Output is correct |
38 |
Correct |
9 ms |
8296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
664 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
5 ms |
604 KB |
Output is correct |
8 |
Correct |
5 ms |
712 KB |
Output is correct |
9 |
Correct |
5 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
784 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8284 KB |
Output is correct |
2 |
Correct |
8 ms |
8284 KB |
Output is correct |
3 |
Correct |
8 ms |
8284 KB |
Output is correct |
4 |
Correct |
8 ms |
8440 KB |
Output is correct |
5 |
Correct |
9 ms |
8280 KB |
Output is correct |
6 |
Correct |
8 ms |
8268 KB |
Output is correct |
7 |
Correct |
9 ms |
8284 KB |
Output is correct |
8 |
Correct |
8 ms |
8284 KB |
Output is correct |
9 |
Correct |
8 ms |
8284 KB |
Output is correct |
10 |
Correct |
10 ms |
8284 KB |
Output is correct |
11 |
Correct |
9 ms |
8284 KB |
Output is correct |
12 |
Correct |
8 ms |
8284 KB |
Output is correct |
13 |
Correct |
9 ms |
8284 KB |
Output is correct |
14 |
Correct |
8 ms |
8284 KB |
Output is correct |
15 |
Correct |
9 ms |
8284 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1884 KB |
Output is correct |
19 |
Correct |
3 ms |
1796 KB |
Output is correct |
20 |
Correct |
2 ms |
1872 KB |
Output is correct |
21 |
Correct |
225 ms |
7636 KB |
Output is correct |
22 |
Correct |
218 ms |
7764 KB |
Output is correct |
23 |
Correct |
196 ms |
7516 KB |
Output is correct |
24 |
Correct |
221 ms |
7516 KB |
Output is correct |
25 |
Correct |
215 ms |
7512 KB |
Output is correct |
26 |
Correct |
415 ms |
7384 KB |
Output is correct |
27 |
Correct |
427 ms |
7512 KB |
Output is correct |
28 |
Correct |
418 ms |
7392 KB |
Output is correct |
29 |
Correct |
418 ms |
7608 KB |
Output is correct |
30 |
Correct |
9 ms |
8284 KB |
Output is correct |
31 |
Correct |
9 ms |
8284 KB |
Output is correct |
32 |
Correct |
9 ms |
8284 KB |
Output is correct |
33 |
Correct |
9 ms |
8284 KB |
Output is correct |
34 |
Correct |
10 ms |
8436 KB |
Output is correct |
35 |
Correct |
9 ms |
8140 KB |
Output is correct |
36 |
Correct |
9 ms |
8336 KB |
Output is correct |
37 |
Correct |
10 ms |
8284 KB |
Output is correct |
38 |
Correct |
9 ms |
8296 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
40 |
Correct |
2 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
664 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
5 ms |
604 KB |
Output is correct |
46 |
Correct |
5 ms |
712 KB |
Output is correct |
47 |
Correct |
5 ms |
860 KB |
Output is correct |
48 |
Correct |
5 ms |
604 KB |
Output is correct |
49 |
Correct |
3 ms |
600 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
52 |
Correct |
2 ms |
604 KB |
Output is correct |
53 |
Correct |
2 ms |
784 KB |
Output is correct |
54 |
Correct |
2 ms |
604 KB |
Output is correct |
55 |
Correct |
2 ms |
604 KB |
Output is correct |
56 |
Correct |
2 ms |
604 KB |
Output is correct |
57 |
Correct |
2 ms |
604 KB |
Output is correct |
58 |
Correct |
2 ms |
456 KB |
Output is correct |
59 |
Correct |
244 ms |
8336 KB |
Output is correct |
60 |
Correct |
226 ms |
8280 KB |
Output is correct |
61 |
Correct |
219 ms |
8528 KB |
Output is correct |
62 |
Correct |
244 ms |
8284 KB |
Output is correct |
63 |
Correct |
238 ms |
8528 KB |
Output is correct |
64 |
Correct |
473 ms |
8332 KB |
Output is correct |
65 |
Correct |
478 ms |
8528 KB |
Output is correct |
66 |
Correct |
477 ms |
8332 KB |
Output is correct |
67 |
Correct |
478 ms |
8280 KB |
Output is correct |
68 |
Correct |
479 ms |
8284 KB |
Output is correct |
69 |
Correct |
196 ms |
8340 KB |
Output is correct |
70 |
Correct |
210 ms |
8284 KB |
Output is correct |
71 |
Correct |
196 ms |
8336 KB |
Output is correct |
72 |
Correct |
203 ms |
8284 KB |
Output is correct |
73 |
Correct |
207 ms |
8280 KB |
Output is correct |
74 |
Correct |
50 ms |
1880 KB |
Output is correct |
75 |
Correct |
51 ms |
1948 KB |
Output is correct |
76 |
Correct |
52 ms |
1884 KB |
Output is correct |
77 |
Correct |
50 ms |
1884 KB |
Output is correct |
78 |
Correct |
52 ms |
1896 KB |
Output is correct |