# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
203917 |
2020-02-23T03:03:50 Z |
Segtree |
Boat (APIO16_boat) |
C++14 |
|
1560 ms |
18840 KB |
#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod
#define N 510
ll po(ll x,ll y){
ll res=1;
for(;y;y>>=1){
if(y&1)mul(res,x);
x=x*x%mod;
}
return res;
}
ll inv[N];
ll C[N][3*N];
void calcc(ll l,ll id){
ll res=1;
C[0][id]=1;
for(ll i=1;i<N;i++){
mul(res,(l+1LL-i));
mul(res,inv[i]);
if(i>l)res=0;
C[i][id]=res;
}
}
ll f[N][2*N];
void initf(ll l,ll m,ll id){
ll res=0;
for(int i=1;i<=m;i++){
mad(res,C[i][id]*C[i-1][2*N+m-1]);
}
f[m][id]=res;
}
ll n,a[N],b[N];
ll rui[2*N][N];
vector<ll> xs;
ll edge(ll j,ll i,ll ii){
ll m=rui[j][ii]-rui[j][i];
return f[m][j];
}
ll dp[N][2*N];
int main(){
for(int i=1;i<N;i++)inv[i]=po(i,mod-2);
cin>>n;
a[0]=b[0]=0;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
}
a[n+1]=2e9,b[n+1]=2e9;
for(int i=0;i<=n+1;i++){
b[i]++;
xs.push_back(a[i]);
xs.push_back(b[i]);
}
sort(all(xs));
xs.erase(unique(all(xs)),xs.end());
for(int i=0;i<=n+1;i++){
a[i]=lower_bound(all(xs),a[i])-xs.begin();
b[i]=lower_bound(all(xs),b[i])-xs.begin();
}
rep(i,N)calcc(i,i+2*N);
for(int i=0;i<xs.size()-1;i++){
calcc(xs[i+1]-xs[i],i);
for(int m=1;m<N;m++)initf(xs[i+1]-xs[i],m,i);
}
rep(j,xs.size()-1){
rui[j][0]=0;
for(int i=0;i<=n+1;i++){
rui[j][i+1]=rui[j][i]+(a[i]<=j&&j<b[i]);
}
}
for(int i=0;i<=n+1;i++)rep(j,xs.size()-1)dp[i][j]=0;
dp[0][0]=1;
for(int ii=1;ii<=n+1;ii++){
for(int jj=a[ii];jj<b[ii];jj++){
if(jj>a[ii])mad(dp[ii][jj],dp[ii][jj-1]);
for(int i=0;i<ii;i++)for(int j=(jj==a[ii]?0:jj-1);j<jj;j++){
mad(dp[ii][jj],dp[i][j]*edge(j,i,ii));
}
}
}
ll ans=dp[n+1][a[n+1]]+mod-1; ans%=mod;
cout<<ans<<endl;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:75:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<xs.size()-1;i++){
~^~~~~~~~~~~~
boat.cpp:10:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,n) for(int i=0;i<n;i++)
boat.cpp:79:6:
rep(j,xs.size()-1){
~~~~~~~~~~~~~
boat.cpp:79:2: note: in expansion of macro 'rep'
rep(j,xs.size()-1){
^~~
boat.cpp:10:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,n) for(int i=0;i<n;i++)
boat.cpp:85:29:
for(int i=0;i<=n+1;i++)rep(j,xs.size()-1)dp[i][j]=0;
~~~~~~~~~~~~~
boat.cpp:85:25: note: in expansion of macro 'rep'
for(int i=0;i<=n+1;i++)rep(j,xs.size()-1)dp[i][j]=0;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1025 ms |
18544 KB |
Output is correct |
2 |
Correct |
1018 ms |
18552 KB |
Output is correct |
3 |
Correct |
1056 ms |
18552 KB |
Output is correct |
4 |
Correct |
1012 ms |
18552 KB |
Output is correct |
5 |
Correct |
1026 ms |
18680 KB |
Output is correct |
6 |
Correct |
1154 ms |
18680 KB |
Output is correct |
7 |
Correct |
1170 ms |
18680 KB |
Output is correct |
8 |
Correct |
1135 ms |
18552 KB |
Output is correct |
9 |
Correct |
1145 ms |
18752 KB |
Output is correct |
10 |
Correct |
1168 ms |
18528 KB |
Output is correct |
11 |
Correct |
1168 ms |
18680 KB |
Output is correct |
12 |
Correct |
1154 ms |
18552 KB |
Output is correct |
13 |
Correct |
1150 ms |
18840 KB |
Output is correct |
14 |
Correct |
1172 ms |
18680 KB |
Output is correct |
15 |
Correct |
1173 ms |
18552 KB |
Output is correct |
16 |
Correct |
168 ms |
11256 KB |
Output is correct |
17 |
Correct |
181 ms |
11588 KB |
Output is correct |
18 |
Correct |
172 ms |
11384 KB |
Output is correct |
19 |
Correct |
177 ms |
11512 KB |
Output is correct |
20 |
Correct |
178 ms |
11468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1025 ms |
18544 KB |
Output is correct |
2 |
Correct |
1018 ms |
18552 KB |
Output is correct |
3 |
Correct |
1056 ms |
18552 KB |
Output is correct |
4 |
Correct |
1012 ms |
18552 KB |
Output is correct |
5 |
Correct |
1026 ms |
18680 KB |
Output is correct |
6 |
Correct |
1154 ms |
18680 KB |
Output is correct |
7 |
Correct |
1170 ms |
18680 KB |
Output is correct |
8 |
Correct |
1135 ms |
18552 KB |
Output is correct |
9 |
Correct |
1145 ms |
18752 KB |
Output is correct |
10 |
Correct |
1168 ms |
18528 KB |
Output is correct |
11 |
Correct |
1168 ms |
18680 KB |
Output is correct |
12 |
Correct |
1154 ms |
18552 KB |
Output is correct |
13 |
Correct |
1150 ms |
18840 KB |
Output is correct |
14 |
Correct |
1172 ms |
18680 KB |
Output is correct |
15 |
Correct |
1173 ms |
18552 KB |
Output is correct |
16 |
Correct |
168 ms |
11256 KB |
Output is correct |
17 |
Correct |
181 ms |
11588 KB |
Output is correct |
18 |
Correct |
172 ms |
11384 KB |
Output is correct |
19 |
Correct |
177 ms |
11512 KB |
Output is correct |
20 |
Correct |
178 ms |
11468 KB |
Output is correct |
21 |
Correct |
1168 ms |
18296 KB |
Output is correct |
22 |
Correct |
1153 ms |
18260 KB |
Output is correct |
23 |
Correct |
1128 ms |
18284 KB |
Output is correct |
24 |
Correct |
1137 ms |
18200 KB |
Output is correct |
25 |
Correct |
1144 ms |
18296 KB |
Output is correct |
26 |
Correct |
1331 ms |
18040 KB |
Output is correct |
27 |
Correct |
1367 ms |
18312 KB |
Output is correct |
28 |
Correct |
1314 ms |
18168 KB |
Output is correct |
29 |
Correct |
1316 ms |
18200 KB |
Output is correct |
30 |
Correct |
1157 ms |
18680 KB |
Output is correct |
31 |
Correct |
1154 ms |
18552 KB |
Output is correct |
32 |
Correct |
1166 ms |
18664 KB |
Output is correct |
33 |
Correct |
1159 ms |
18680 KB |
Output is correct |
34 |
Correct |
1148 ms |
18680 KB |
Output is correct |
35 |
Correct |
1006 ms |
18552 KB |
Output is correct |
36 |
Correct |
1020 ms |
18552 KB |
Output is correct |
37 |
Correct |
1006 ms |
18680 KB |
Output is correct |
38 |
Correct |
1027 ms |
18552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
9336 KB |
Output is correct |
2 |
Correct |
145 ms |
9336 KB |
Output is correct |
3 |
Correct |
143 ms |
9340 KB |
Output is correct |
4 |
Correct |
149 ms |
9592 KB |
Output is correct |
5 |
Correct |
143 ms |
9592 KB |
Output is correct |
6 |
Correct |
143 ms |
9336 KB |
Output is correct |
7 |
Correct |
148 ms |
9464 KB |
Output is correct |
8 |
Correct |
146 ms |
9464 KB |
Output is correct |
9 |
Correct |
144 ms |
9464 KB |
Output is correct |
10 |
Correct |
152 ms |
9428 KB |
Output is correct |
11 |
Correct |
143 ms |
9336 KB |
Output is correct |
12 |
Correct |
148 ms |
9464 KB |
Output is correct |
13 |
Correct |
145 ms |
9336 KB |
Output is correct |
14 |
Correct |
144 ms |
9336 KB |
Output is correct |
15 |
Correct |
144 ms |
9336 KB |
Output is correct |
16 |
Correct |
92 ms |
8312 KB |
Output is correct |
17 |
Correct |
86 ms |
8184 KB |
Output is correct |
18 |
Correct |
87 ms |
8312 KB |
Output is correct |
19 |
Correct |
87 ms |
8312 KB |
Output is correct |
20 |
Correct |
88 ms |
8344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1025 ms |
18544 KB |
Output is correct |
2 |
Correct |
1018 ms |
18552 KB |
Output is correct |
3 |
Correct |
1056 ms |
18552 KB |
Output is correct |
4 |
Correct |
1012 ms |
18552 KB |
Output is correct |
5 |
Correct |
1026 ms |
18680 KB |
Output is correct |
6 |
Correct |
1154 ms |
18680 KB |
Output is correct |
7 |
Correct |
1170 ms |
18680 KB |
Output is correct |
8 |
Correct |
1135 ms |
18552 KB |
Output is correct |
9 |
Correct |
1145 ms |
18752 KB |
Output is correct |
10 |
Correct |
1168 ms |
18528 KB |
Output is correct |
11 |
Correct |
1168 ms |
18680 KB |
Output is correct |
12 |
Correct |
1154 ms |
18552 KB |
Output is correct |
13 |
Correct |
1150 ms |
18840 KB |
Output is correct |
14 |
Correct |
1172 ms |
18680 KB |
Output is correct |
15 |
Correct |
1173 ms |
18552 KB |
Output is correct |
16 |
Correct |
168 ms |
11256 KB |
Output is correct |
17 |
Correct |
181 ms |
11588 KB |
Output is correct |
18 |
Correct |
172 ms |
11384 KB |
Output is correct |
19 |
Correct |
177 ms |
11512 KB |
Output is correct |
20 |
Correct |
178 ms |
11468 KB |
Output is correct |
21 |
Correct |
1168 ms |
18296 KB |
Output is correct |
22 |
Correct |
1153 ms |
18260 KB |
Output is correct |
23 |
Correct |
1128 ms |
18284 KB |
Output is correct |
24 |
Correct |
1137 ms |
18200 KB |
Output is correct |
25 |
Correct |
1144 ms |
18296 KB |
Output is correct |
26 |
Correct |
1331 ms |
18040 KB |
Output is correct |
27 |
Correct |
1367 ms |
18312 KB |
Output is correct |
28 |
Correct |
1314 ms |
18168 KB |
Output is correct |
29 |
Correct |
1316 ms |
18200 KB |
Output is correct |
30 |
Correct |
1157 ms |
18680 KB |
Output is correct |
31 |
Correct |
1154 ms |
18552 KB |
Output is correct |
32 |
Correct |
1166 ms |
18664 KB |
Output is correct |
33 |
Correct |
1159 ms |
18680 KB |
Output is correct |
34 |
Correct |
1148 ms |
18680 KB |
Output is correct |
35 |
Correct |
1006 ms |
18552 KB |
Output is correct |
36 |
Correct |
1020 ms |
18552 KB |
Output is correct |
37 |
Correct |
1006 ms |
18680 KB |
Output is correct |
38 |
Correct |
1027 ms |
18552 KB |
Output is correct |
39 |
Correct |
145 ms |
9336 KB |
Output is correct |
40 |
Correct |
145 ms |
9336 KB |
Output is correct |
41 |
Correct |
143 ms |
9340 KB |
Output is correct |
42 |
Correct |
149 ms |
9592 KB |
Output is correct |
43 |
Correct |
143 ms |
9592 KB |
Output is correct |
44 |
Correct |
143 ms |
9336 KB |
Output is correct |
45 |
Correct |
148 ms |
9464 KB |
Output is correct |
46 |
Correct |
146 ms |
9464 KB |
Output is correct |
47 |
Correct |
144 ms |
9464 KB |
Output is correct |
48 |
Correct |
152 ms |
9428 KB |
Output is correct |
49 |
Correct |
143 ms |
9336 KB |
Output is correct |
50 |
Correct |
148 ms |
9464 KB |
Output is correct |
51 |
Correct |
145 ms |
9336 KB |
Output is correct |
52 |
Correct |
144 ms |
9336 KB |
Output is correct |
53 |
Correct |
144 ms |
9336 KB |
Output is correct |
54 |
Correct |
92 ms |
8312 KB |
Output is correct |
55 |
Correct |
86 ms |
8184 KB |
Output is correct |
56 |
Correct |
87 ms |
8312 KB |
Output is correct |
57 |
Correct |
87 ms |
8312 KB |
Output is correct |
58 |
Correct |
88 ms |
8344 KB |
Output is correct |
59 |
Correct |
1287 ms |
18680 KB |
Output is correct |
60 |
Correct |
1274 ms |
18680 KB |
Output is correct |
61 |
Correct |
1272 ms |
18800 KB |
Output is correct |
62 |
Correct |
1292 ms |
18552 KB |
Output is correct |
63 |
Correct |
1295 ms |
18620 KB |
Output is correct |
64 |
Correct |
1526 ms |
18680 KB |
Output is correct |
65 |
Correct |
1560 ms |
18648 KB |
Output is correct |
66 |
Correct |
1549 ms |
18680 KB |
Output is correct |
67 |
Correct |
1555 ms |
18552 KB |
Output is correct |
68 |
Correct |
1548 ms |
18744 KB |
Output is correct |
69 |
Correct |
1352 ms |
18552 KB |
Output is correct |
70 |
Correct |
1347 ms |
18628 KB |
Output is correct |
71 |
Correct |
1339 ms |
18680 KB |
Output is correct |
72 |
Correct |
1374 ms |
18748 KB |
Output is correct |
73 |
Correct |
1406 ms |
18552 KB |
Output is correct |
74 |
Correct |
240 ms |
11512 KB |
Output is correct |
75 |
Correct |
236 ms |
11512 KB |
Output is correct |
76 |
Correct |
246 ms |
11384 KB |
Output is correct |
77 |
Correct |
234 ms |
11384 KB |
Output is correct |
78 |
Correct |
229 ms |
11384 KB |
Output is correct |