# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
200584 |
2020-02-07T13:06:13 Z |
red1108 |
Boat (APIO16_boat) |
C++17 |
|
1531 ms |
14640 KB |
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 2e16;
const int inf = 2e9;
template<class T>
void pr(T t) {cout << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cout << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cout << endl <<endl;}
int in[510][2], n;
vector<int> h;
int cnt[1010];
ll dp[510][1010],mod=1e9+7,ncr[510][510],choice[1010][510],iinv[510],ndr[1010][510];
ll mypow(ll a, ll b){
ll ret=1;
while(b){
if(b&1) ret = ret*a%mod;
a=a*a%mod;
b>>=1;
}
return ret;
}
int main(){
fastio;
cin>>n;
h.eb(0);
for(int i=1;i<=n;i++){
cin>>in[i][0]>>in[i][1];in[i][1]++;
h.eb(in[i][0]);h.eb(in[i][1]);
}
ncr[0][0]=1;
for(int i=1;i<=n;i++){
ncr[i][0]=1;
for(int j=1;j<=i;j++) ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%mod;
}
for(int i=1;i<=n;i++) iinv[i]=mypow(i,mod-2);
sort(h.begin(),h.end());
h.resize(unique(all(h))-h.begin());
for(int i=1;i<=n;i++){
in[i][0]=lower_bound(all(h),in[i][0])-h.begin();
in[i][1]=lower_bound(all(h),in[i][1])-h.begin();
for(int j=in[i][0];j<in[i][1];j++) cnt[j]++;
}
for(int j=1;j<h.size()-1;j++){
ll m = h[j+1]-h[j], c = 1;
ndr[j][0]=1;
for(int i=1;i<=n;i++){
if(i>m) break;
c = c * (m-i+1)%mod * iinv[i]%mod;
ndr[j][i]=c;
}
}
for(int j=1;j<h.size()-1;j++){
choice[j][1]=h[j+1]-h[j];
for(int s=2;s<=cnt[j];s++){
choice[j][s]=choice[j][s-1];
for(int i=2;i<=s;i++)
choice[j][s] = (choice[j][s] + ndr[j][i] * ncr[s-2][i-2] ) %mod;
}
}
/*
for(int i=1;i<h.size()-1;i++){
for(int j=1;j<=cnt[j];j++) printf("ch[%d][%d]=%lld\n",i,j,choice[i][j]);
}*/
ll ans=0;
in[0][1]=1;
for(int i=0;i<=2*n;i++) dp[0][i]=1;
for(int i=1;i<=n;i++){
if(i==1){
for(int j=in[i][0];j<in[i][1];j++) dp[i][j]=dp[i][j-1]+h[j+1]-h[j];
continue;
}
for(int j=in[i][0];j<in[i][1];j++){
dp[i][j]=dp[i][j-1];
int num=0;
for(int k=i;k>=1;k--){
if(in[k][0]<=j&&j<in[k][1]) num++;
//prl("i=",i,"j=",j,"k=",k,"num=",num,"choice=",choice[j][num]);
int x = min(in[k-1][1]-1,j-1);
dp[i][j]=(dp[i][j]+dp[k-1][x]*choice[j][num]%mod)%mod;
}
}
}
/*
prl("debuggggg");
for(int i=1;i<=n;i++){
for(int j=in[i][0];j<in[i][1];j++) printf("dp[%d][%d]=%lld\n",i,j,dp[i][j]);
}
*/
for(int i=1;i<=n;i++){
ans = (ans + dp[i][in[i][1]-1])%mod;
}
cout<<ans;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<h.size()-1;j++){
~^~~~~~~~~~~
boat.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<h.size()-1;j++){
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
12280 KB |
Output is correct |
2 |
Correct |
19 ms |
12280 KB |
Output is correct |
3 |
Correct |
20 ms |
12280 KB |
Output is correct |
4 |
Correct |
22 ms |
12280 KB |
Output is correct |
5 |
Correct |
18 ms |
12284 KB |
Output is correct |
6 |
Correct |
20 ms |
12280 KB |
Output is correct |
7 |
Correct |
18 ms |
12408 KB |
Output is correct |
8 |
Correct |
18 ms |
12412 KB |
Output is correct |
9 |
Correct |
19 ms |
12408 KB |
Output is correct |
10 |
Correct |
20 ms |
12412 KB |
Output is correct |
11 |
Correct |
19 ms |
12408 KB |
Output is correct |
12 |
Correct |
18 ms |
12408 KB |
Output is correct |
13 |
Correct |
18 ms |
12408 KB |
Output is correct |
14 |
Correct |
19 ms |
12408 KB |
Output is correct |
15 |
Correct |
19 ms |
12408 KB |
Output is correct |
16 |
Correct |
12 ms |
5752 KB |
Output is correct |
17 |
Correct |
11 ms |
5884 KB |
Output is correct |
18 |
Correct |
11 ms |
5880 KB |
Output is correct |
19 |
Correct |
11 ms |
5880 KB |
Output is correct |
20 |
Correct |
11 ms |
5880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
12280 KB |
Output is correct |
2 |
Correct |
19 ms |
12280 KB |
Output is correct |
3 |
Correct |
20 ms |
12280 KB |
Output is correct |
4 |
Correct |
22 ms |
12280 KB |
Output is correct |
5 |
Correct |
18 ms |
12284 KB |
Output is correct |
6 |
Correct |
20 ms |
12280 KB |
Output is correct |
7 |
Correct |
18 ms |
12408 KB |
Output is correct |
8 |
Correct |
18 ms |
12412 KB |
Output is correct |
9 |
Correct |
19 ms |
12408 KB |
Output is correct |
10 |
Correct |
20 ms |
12412 KB |
Output is correct |
11 |
Correct |
19 ms |
12408 KB |
Output is correct |
12 |
Correct |
18 ms |
12408 KB |
Output is correct |
13 |
Correct |
18 ms |
12408 KB |
Output is correct |
14 |
Correct |
19 ms |
12408 KB |
Output is correct |
15 |
Correct |
19 ms |
12408 KB |
Output is correct |
16 |
Correct |
12 ms |
5752 KB |
Output is correct |
17 |
Correct |
11 ms |
5884 KB |
Output is correct |
18 |
Correct |
11 ms |
5880 KB |
Output is correct |
19 |
Correct |
11 ms |
5880 KB |
Output is correct |
20 |
Correct |
11 ms |
5880 KB |
Output is correct |
21 |
Correct |
621 ms |
12920 KB |
Output is correct |
22 |
Correct |
592 ms |
12920 KB |
Output is correct |
23 |
Correct |
558 ms |
12796 KB |
Output is correct |
24 |
Correct |
594 ms |
12536 KB |
Output is correct |
25 |
Correct |
605 ms |
12792 KB |
Output is correct |
26 |
Correct |
952 ms |
13304 KB |
Output is correct |
27 |
Correct |
967 ms |
13304 KB |
Output is correct |
28 |
Correct |
962 ms |
13188 KB |
Output is correct |
29 |
Correct |
951 ms |
13004 KB |
Output is correct |
30 |
Correct |
21 ms |
12280 KB |
Output is correct |
31 |
Correct |
21 ms |
12408 KB |
Output is correct |
32 |
Correct |
21 ms |
12280 KB |
Output is correct |
33 |
Correct |
22 ms |
12408 KB |
Output is correct |
34 |
Correct |
22 ms |
12308 KB |
Output is correct |
35 |
Correct |
20 ms |
12280 KB |
Output is correct |
36 |
Correct |
21 ms |
12344 KB |
Output is correct |
37 |
Correct |
21 ms |
12280 KB |
Output is correct |
38 |
Correct |
23 ms |
12280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2808 KB |
Output is correct |
2 |
Correct |
11 ms |
2808 KB |
Output is correct |
3 |
Correct |
13 ms |
2936 KB |
Output is correct |
4 |
Correct |
13 ms |
2828 KB |
Output is correct |
5 |
Correct |
13 ms |
2808 KB |
Output is correct |
6 |
Correct |
18 ms |
2936 KB |
Output is correct |
7 |
Correct |
19 ms |
2808 KB |
Output is correct |
8 |
Correct |
18 ms |
2968 KB |
Output is correct |
9 |
Correct |
18 ms |
2808 KB |
Output is correct |
10 |
Correct |
17 ms |
2936 KB |
Output is correct |
11 |
Correct |
13 ms |
2936 KB |
Output is correct |
12 |
Correct |
12 ms |
2808 KB |
Output is correct |
13 |
Correct |
12 ms |
2808 KB |
Output is correct |
14 |
Correct |
13 ms |
2936 KB |
Output is correct |
15 |
Correct |
13 ms |
2936 KB |
Output is correct |
16 |
Correct |
10 ms |
2144 KB |
Output is correct |
17 |
Correct |
9 ms |
2168 KB |
Output is correct |
18 |
Correct |
11 ms |
2168 KB |
Output is correct |
19 |
Correct |
9 ms |
2168 KB |
Output is correct |
20 |
Correct |
10 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
12280 KB |
Output is correct |
2 |
Correct |
19 ms |
12280 KB |
Output is correct |
3 |
Correct |
20 ms |
12280 KB |
Output is correct |
4 |
Correct |
22 ms |
12280 KB |
Output is correct |
5 |
Correct |
18 ms |
12284 KB |
Output is correct |
6 |
Correct |
20 ms |
12280 KB |
Output is correct |
7 |
Correct |
18 ms |
12408 KB |
Output is correct |
8 |
Correct |
18 ms |
12412 KB |
Output is correct |
9 |
Correct |
19 ms |
12408 KB |
Output is correct |
10 |
Correct |
20 ms |
12412 KB |
Output is correct |
11 |
Correct |
19 ms |
12408 KB |
Output is correct |
12 |
Correct |
18 ms |
12408 KB |
Output is correct |
13 |
Correct |
18 ms |
12408 KB |
Output is correct |
14 |
Correct |
19 ms |
12408 KB |
Output is correct |
15 |
Correct |
19 ms |
12408 KB |
Output is correct |
16 |
Correct |
12 ms |
5752 KB |
Output is correct |
17 |
Correct |
11 ms |
5884 KB |
Output is correct |
18 |
Correct |
11 ms |
5880 KB |
Output is correct |
19 |
Correct |
11 ms |
5880 KB |
Output is correct |
20 |
Correct |
11 ms |
5880 KB |
Output is correct |
21 |
Correct |
621 ms |
12920 KB |
Output is correct |
22 |
Correct |
592 ms |
12920 KB |
Output is correct |
23 |
Correct |
558 ms |
12796 KB |
Output is correct |
24 |
Correct |
594 ms |
12536 KB |
Output is correct |
25 |
Correct |
605 ms |
12792 KB |
Output is correct |
26 |
Correct |
952 ms |
13304 KB |
Output is correct |
27 |
Correct |
967 ms |
13304 KB |
Output is correct |
28 |
Correct |
962 ms |
13188 KB |
Output is correct |
29 |
Correct |
951 ms |
13004 KB |
Output is correct |
30 |
Correct |
21 ms |
12280 KB |
Output is correct |
31 |
Correct |
21 ms |
12408 KB |
Output is correct |
32 |
Correct |
21 ms |
12280 KB |
Output is correct |
33 |
Correct |
22 ms |
12408 KB |
Output is correct |
34 |
Correct |
22 ms |
12308 KB |
Output is correct |
35 |
Correct |
20 ms |
12280 KB |
Output is correct |
36 |
Correct |
21 ms |
12344 KB |
Output is correct |
37 |
Correct |
21 ms |
12280 KB |
Output is correct |
38 |
Correct |
23 ms |
12280 KB |
Output is correct |
39 |
Correct |
13 ms |
2808 KB |
Output is correct |
40 |
Correct |
11 ms |
2808 KB |
Output is correct |
41 |
Correct |
13 ms |
2936 KB |
Output is correct |
42 |
Correct |
13 ms |
2828 KB |
Output is correct |
43 |
Correct |
13 ms |
2808 KB |
Output is correct |
44 |
Correct |
18 ms |
2936 KB |
Output is correct |
45 |
Correct |
19 ms |
2808 KB |
Output is correct |
46 |
Correct |
18 ms |
2968 KB |
Output is correct |
47 |
Correct |
18 ms |
2808 KB |
Output is correct |
48 |
Correct |
17 ms |
2936 KB |
Output is correct |
49 |
Correct |
13 ms |
2936 KB |
Output is correct |
50 |
Correct |
12 ms |
2808 KB |
Output is correct |
51 |
Correct |
12 ms |
2808 KB |
Output is correct |
52 |
Correct |
13 ms |
2936 KB |
Output is correct |
53 |
Correct |
13 ms |
2936 KB |
Output is correct |
54 |
Correct |
10 ms |
2144 KB |
Output is correct |
55 |
Correct |
9 ms |
2168 KB |
Output is correct |
56 |
Correct |
11 ms |
2168 KB |
Output is correct |
57 |
Correct |
9 ms |
2168 KB |
Output is correct |
58 |
Correct |
10 ms |
2040 KB |
Output is correct |
59 |
Correct |
859 ms |
13492 KB |
Output is correct |
60 |
Correct |
811 ms |
13444 KB |
Output is correct |
61 |
Correct |
763 ms |
13416 KB |
Output is correct |
62 |
Correct |
860 ms |
13452 KB |
Output is correct |
63 |
Correct |
838 ms |
13384 KB |
Output is correct |
64 |
Correct |
1501 ms |
14640 KB |
Output is correct |
65 |
Correct |
1483 ms |
14376 KB |
Output is correct |
66 |
Correct |
1493 ms |
14328 KB |
Output is correct |
67 |
Correct |
1490 ms |
14456 KB |
Output is correct |
68 |
Correct |
1531 ms |
14456 KB |
Output is correct |
69 |
Correct |
704 ms |
13560 KB |
Output is correct |
70 |
Correct |
695 ms |
13432 KB |
Output is correct |
71 |
Correct |
691 ms |
13688 KB |
Output is correct |
72 |
Correct |
725 ms |
13564 KB |
Output is correct |
73 |
Correct |
741 ms |
13816 KB |
Output is correct |
74 |
Correct |
144 ms |
6136 KB |
Output is correct |
75 |
Correct |
136 ms |
6224 KB |
Output is correct |
76 |
Correct |
143 ms |
6136 KB |
Output is correct |
77 |
Correct |
142 ms |
6136 KB |
Output is correct |
78 |
Correct |
147 ms |
6140 KB |
Output is correct |