# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
793031 |
2023-07-25T12:49:58 Z |
algorithm16 |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
15128 KB |
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int n,a[505],b[505],dp[1505][2][505][2],inv[505],m[1505][505],mod=1e9+7;
vector <int> v,v1;
vector <vector<int> > v2;
int sum(int a,int b) {
return (a+b)%mod;
}
int mul(int a,int b) {
return ((long long)a*b)%mod;
}
int exp(int a,int b) {
if(!b) return 1;
int ret=exp(a,b/2);
if(b%2==0) return mul(ret,ret);
return mul(mul(ret,ret),a);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i=0;i<n;i++) {
cin >> a[i] >> b[i];
v.push_back(a[i]);
v.push_back(b[i]);
v.push_back(b[i]+1);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
/*for(int i=0;i<v.size()-1;i++) {
cout << v[i] << " " << v[i+1]-1 << "\n";
}*/
/*for(int i=0;i<n;i++) {
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
b[i]=lower_bound(v.begin(),v.end(),b[i])-v.begin();
}*/
for(int i=1;i<=n;i++) {
inv[i]=exp(i,mod-2);
}
for(int i=0;i<v.size()-1;i++) {
for(int j=0;j<=n;j++) {
dp[i][n%2][j][0]=1;
dp[i][n%2][j][1]=1;
}
}
for(int i=0;i<v.size()-1;i++) {
for(int j=0;j<n;j++) {
m[i][j]=mul(v[i+1]-v[i]-j,inv[j+1]);
}
}
for(int x=n-1;x>=0;x--) {
for(int idx=v.size()-2;idx>=0;idx--) {
for(int cnt=0;cnt<=x;cnt++) {
for(int a1=0;a1<2;a1++) {
int ret=0;
if(!a1) ret=sum(ret,dp[idx][(x+1)%2][cnt][0]); // 0
if(v[idx+1]-1<=b[x]) {
if(v[idx]>=a[x] && v[idx+1]-1<=b[x]) {
if(cnt<=v[idx+1]-1-v[idx]) ret=sum(ret,mul(dp[idx][(x+1)%2][cnt+1][0],m[idx][cnt]));
}
ret=sum(ret,dp[idx+1][x%2][0][1]);
}
dp[idx][x%2][cnt][a1]=ret;
//cout << idx << " " << x << " " << cnt << " " << a1 << " " << ret << "\n";
}
}
}
}
cout << dp[0][0][0][0]-1;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i<v.size()-1;i++) {
| ~^~~~~~~~~~~
boat.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<v.size()-1;i++) {
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1102 ms |
10216 KB |
Output is correct |
2 |
Correct |
1094 ms |
10220 KB |
Output is correct |
3 |
Correct |
1094 ms |
10212 KB |
Output is correct |
4 |
Correct |
1077 ms |
10212 KB |
Output is correct |
5 |
Correct |
1091 ms |
10220 KB |
Output is correct |
6 |
Correct |
1262 ms |
10208 KB |
Output is correct |
7 |
Correct |
1259 ms |
10216 KB |
Output is correct |
8 |
Correct |
1254 ms |
10220 KB |
Output is correct |
9 |
Correct |
1255 ms |
10216 KB |
Output is correct |
10 |
Correct |
1258 ms |
10212 KB |
Output is correct |
11 |
Correct |
1257 ms |
10232 KB |
Output is correct |
12 |
Correct |
1254 ms |
10216 KB |
Output is correct |
13 |
Correct |
1262 ms |
10208 KB |
Output is correct |
14 |
Correct |
1267 ms |
10216 KB |
Output is correct |
15 |
Correct |
1255 ms |
10220 KB |
Output is correct |
16 |
Correct |
167 ms |
2004 KB |
Output is correct |
17 |
Correct |
179 ms |
2212 KB |
Output is correct |
18 |
Correct |
176 ms |
2136 KB |
Output is correct |
19 |
Correct |
175 ms |
2132 KB |
Output is correct |
20 |
Correct |
177 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1102 ms |
10216 KB |
Output is correct |
2 |
Correct |
1094 ms |
10220 KB |
Output is correct |
3 |
Correct |
1094 ms |
10212 KB |
Output is correct |
4 |
Correct |
1077 ms |
10212 KB |
Output is correct |
5 |
Correct |
1091 ms |
10220 KB |
Output is correct |
6 |
Correct |
1262 ms |
10208 KB |
Output is correct |
7 |
Correct |
1259 ms |
10216 KB |
Output is correct |
8 |
Correct |
1254 ms |
10220 KB |
Output is correct |
9 |
Correct |
1255 ms |
10216 KB |
Output is correct |
10 |
Correct |
1258 ms |
10212 KB |
Output is correct |
11 |
Correct |
1257 ms |
10232 KB |
Output is correct |
12 |
Correct |
1254 ms |
10216 KB |
Output is correct |
13 |
Correct |
1262 ms |
10208 KB |
Output is correct |
14 |
Correct |
1267 ms |
10216 KB |
Output is correct |
15 |
Correct |
1255 ms |
10220 KB |
Output is correct |
16 |
Correct |
167 ms |
2004 KB |
Output is correct |
17 |
Correct |
179 ms |
2212 KB |
Output is correct |
18 |
Correct |
176 ms |
2136 KB |
Output is correct |
19 |
Correct |
175 ms |
2132 KB |
Output is correct |
20 |
Correct |
177 ms |
2156 KB |
Output is correct |
21 |
Correct |
1620 ms |
13164 KB |
Output is correct |
22 |
Correct |
1600 ms |
13292 KB |
Output is correct |
23 |
Correct |
1570 ms |
13016 KB |
Output is correct |
24 |
Correct |
1573 ms |
13100 KB |
Output is correct |
25 |
Correct |
1599 ms |
13052 KB |
Output is correct |
26 |
Correct |
1710 ms |
12296 KB |
Output is correct |
27 |
Correct |
1763 ms |
12648 KB |
Output is correct |
28 |
Correct |
1716 ms |
12400 KB |
Output is correct |
29 |
Correct |
1717 ms |
12468 KB |
Output is correct |
30 |
Correct |
1838 ms |
14648 KB |
Output is correct |
31 |
Correct |
1840 ms |
14584 KB |
Output is correct |
32 |
Correct |
1830 ms |
14596 KB |
Output is correct |
33 |
Correct |
1830 ms |
14624 KB |
Output is correct |
34 |
Correct |
1822 ms |
14556 KB |
Output is correct |
35 |
Correct |
1076 ms |
10208 KB |
Output is correct |
36 |
Correct |
1088 ms |
10316 KB |
Output is correct |
37 |
Correct |
1087 ms |
10204 KB |
Output is correct |
38 |
Correct |
1104 ms |
10196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
3284 KB |
Output is correct |
2 |
Correct |
22 ms |
3156 KB |
Output is correct |
3 |
Correct |
23 ms |
3284 KB |
Output is correct |
4 |
Correct |
24 ms |
3284 KB |
Output is correct |
5 |
Correct |
25 ms |
3284 KB |
Output is correct |
6 |
Correct |
30 ms |
3264 KB |
Output is correct |
7 |
Correct |
31 ms |
3284 KB |
Output is correct |
8 |
Correct |
30 ms |
3296 KB |
Output is correct |
9 |
Correct |
30 ms |
3156 KB |
Output is correct |
10 |
Correct |
30 ms |
3156 KB |
Output is correct |
11 |
Correct |
25 ms |
3296 KB |
Output is correct |
12 |
Correct |
23 ms |
3284 KB |
Output is correct |
13 |
Correct |
23 ms |
3284 KB |
Output is correct |
14 |
Correct |
23 ms |
3292 KB |
Output is correct |
15 |
Correct |
25 ms |
3284 KB |
Output is correct |
16 |
Correct |
12 ms |
1776 KB |
Output is correct |
17 |
Correct |
12 ms |
1620 KB |
Output is correct |
18 |
Correct |
11 ms |
1728 KB |
Output is correct |
19 |
Correct |
11 ms |
1748 KB |
Output is correct |
20 |
Correct |
12 ms |
1776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1102 ms |
10216 KB |
Output is correct |
2 |
Correct |
1094 ms |
10220 KB |
Output is correct |
3 |
Correct |
1094 ms |
10212 KB |
Output is correct |
4 |
Correct |
1077 ms |
10212 KB |
Output is correct |
5 |
Correct |
1091 ms |
10220 KB |
Output is correct |
6 |
Correct |
1262 ms |
10208 KB |
Output is correct |
7 |
Correct |
1259 ms |
10216 KB |
Output is correct |
8 |
Correct |
1254 ms |
10220 KB |
Output is correct |
9 |
Correct |
1255 ms |
10216 KB |
Output is correct |
10 |
Correct |
1258 ms |
10212 KB |
Output is correct |
11 |
Correct |
1257 ms |
10232 KB |
Output is correct |
12 |
Correct |
1254 ms |
10216 KB |
Output is correct |
13 |
Correct |
1262 ms |
10208 KB |
Output is correct |
14 |
Correct |
1267 ms |
10216 KB |
Output is correct |
15 |
Correct |
1255 ms |
10220 KB |
Output is correct |
16 |
Correct |
167 ms |
2004 KB |
Output is correct |
17 |
Correct |
179 ms |
2212 KB |
Output is correct |
18 |
Correct |
176 ms |
2136 KB |
Output is correct |
19 |
Correct |
175 ms |
2132 KB |
Output is correct |
20 |
Correct |
177 ms |
2156 KB |
Output is correct |
21 |
Correct |
1620 ms |
13164 KB |
Output is correct |
22 |
Correct |
1600 ms |
13292 KB |
Output is correct |
23 |
Correct |
1570 ms |
13016 KB |
Output is correct |
24 |
Correct |
1573 ms |
13100 KB |
Output is correct |
25 |
Correct |
1599 ms |
13052 KB |
Output is correct |
26 |
Correct |
1710 ms |
12296 KB |
Output is correct |
27 |
Correct |
1763 ms |
12648 KB |
Output is correct |
28 |
Correct |
1716 ms |
12400 KB |
Output is correct |
29 |
Correct |
1717 ms |
12468 KB |
Output is correct |
30 |
Correct |
1838 ms |
14648 KB |
Output is correct |
31 |
Correct |
1840 ms |
14584 KB |
Output is correct |
32 |
Correct |
1830 ms |
14596 KB |
Output is correct |
33 |
Correct |
1830 ms |
14624 KB |
Output is correct |
34 |
Correct |
1822 ms |
14556 KB |
Output is correct |
35 |
Correct |
1076 ms |
10208 KB |
Output is correct |
36 |
Correct |
1088 ms |
10316 KB |
Output is correct |
37 |
Correct |
1087 ms |
10204 KB |
Output is correct |
38 |
Correct |
1104 ms |
10196 KB |
Output is correct |
39 |
Correct |
24 ms |
3284 KB |
Output is correct |
40 |
Correct |
22 ms |
3156 KB |
Output is correct |
41 |
Correct |
23 ms |
3284 KB |
Output is correct |
42 |
Correct |
24 ms |
3284 KB |
Output is correct |
43 |
Correct |
25 ms |
3284 KB |
Output is correct |
44 |
Correct |
30 ms |
3264 KB |
Output is correct |
45 |
Correct |
31 ms |
3284 KB |
Output is correct |
46 |
Correct |
30 ms |
3296 KB |
Output is correct |
47 |
Correct |
30 ms |
3156 KB |
Output is correct |
48 |
Correct |
30 ms |
3156 KB |
Output is correct |
49 |
Correct |
25 ms |
3296 KB |
Output is correct |
50 |
Correct |
23 ms |
3284 KB |
Output is correct |
51 |
Correct |
23 ms |
3284 KB |
Output is correct |
52 |
Correct |
23 ms |
3292 KB |
Output is correct |
53 |
Correct |
25 ms |
3284 KB |
Output is correct |
54 |
Correct |
12 ms |
1776 KB |
Output is correct |
55 |
Correct |
12 ms |
1620 KB |
Output is correct |
56 |
Correct |
11 ms |
1728 KB |
Output is correct |
57 |
Correct |
11 ms |
1748 KB |
Output is correct |
58 |
Correct |
12 ms |
1776 KB |
Output is correct |
59 |
Execution timed out |
2079 ms |
15128 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |