# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
199836 |
2020-02-03T15:30:48 Z |
ansol4328 |
Boat (APIO16_boat) |
C++14 |
|
99 ms |
4344 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int n, m[505][2];
ll inv[505], cnt[1005], dp[505][1005], sel[505];
vector<ll> lst;
ll get_pow(ll x, ll p)
{
if(p==0) return 1;
if(p==1) return x;
ll ret=get_pow(x,p>>1);
(ret*=ret)%=MOD;
if(p&1) (ret*=x)%=MOD;
return ret;
}
void init()
{
ll fac=1;
inv[0]=1;
for(ll i=1 ; i<=n ; i++) (fac*=i)%=MOD;
inv[n]=get_pow(fac,MOD-2);
for(ll i=n ; i>=1 ; i--) inv[i-1]=(inv[i]*i)%MOD;
for(int i=1 ; i<=n ; i++){
if(m[i][0]==1) dp[i][1]=1;
(dp[i][1]+=dp[i-1][1])%=MOD;
}
dp[1][m[1][0]]=1;
for(int i=m[1][0]+1 ; i<=m[1][1] ; i++) dp[1][i]=(dp[1][i-1]+(lst[i-1]-lst[i-2]))%MOD;
for(int i=m[1][1]+1 ; i<=(int)lst.size() ; i++) dp[1][i]=dp[1][i-1];
for(int i=1 ; i<=(int)lst.size() ; i++){
for(int j=1 ; j<=n ; j++){
if(m[j][0]<i && i<=m[j][1]) cnt[i]++;
}
}
}
void calc_sel(ll L, ll K)
{
ll lim=min(L,K);
if(lim<2) return;
for(ll i=2 ; i<=K ; i++){
ll v1=1, v2=(L*(L-1))%MOD;
ll val1, val2;
sel[i]=(v2*(inv[2]))%MOD;
for(ll j=3, x1=i-2, x2=L-2 ; j<=min(lim,i) ; j++, x1--, x2--){
(v1*=x1)%=MOD;
(v2*=x2)%=MOD;
val1=(v1*inv[j-2])%MOD, val2=(v2*inv[j])%MOD;
sel[i]+=(val1*val2)%MOD;
sel[i]%=MOD;
}
}
}
int main()
{
scanf("%d",&n);
for(int i=1 ; i<=n ; i++){
scanf("%d %d",&m[i][0],&m[i][1]);
lst.push_back((ll)m[i][0]);
lst.push_back((ll)m[i][1]);
}
//contraction
sort(lst.begin(),lst.end());
lst.erase(unique(lst.begin(),lst.end()),lst.end());
for(int i=1 ; i<=n ; i++){
m[i][0]=lower_bound(lst.begin(),lst.end(),(ll)m[i][0])-lst.begin()+1;
m[i][1]=lower_bound(lst.begin(),lst.end(),(ll)m[i][1])-lst.begin()+1;
}
init();
//solve
for(int i=2 ; i<=(int)lst.size() ; i++){
ll L=lst[i-1]-lst[i-2];
if(cnt[i]>1) calc_sel(L,cnt[i]);
for(int j=2 ; j<=n ; j++){
(dp[j][i]+=dp[j-1][i])%=MOD;
(dp[j][i]+=dp[j][i-1])%=MOD;
dp[j][i]=(dp[j][i]-dp[j-1][i-1]+MOD)%MOD;
if(i<m[j][0] || m[j][1]<i) continue;
if(i==m[j][0] || L==1){
(dp[j][i]+=dp[j-1][i-1]+1)%=MOD;
continue;
}
ll val=(dp[j-1][i-1]*L+L)%MOD, c=1;
for(int k=j-1 ; k>=1 ; k--){
if(m[k][0]<i && i<=m[k][1]){
c++;
if(k!=1) (val+=sel[c]*dp[k-1][i-1])%=MOD;
else (val+=sel[c])%=MOD;
}
}
(dp[j][i]+=val)%=MOD;
}
}
printf("%lld",dp[n][(int)lst.size()]);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
boat.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&m[i][0],&m[i][1]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4216 KB |
Output is correct |
2 |
Correct |
12 ms |
4088 KB |
Output is correct |
3 |
Correct |
13 ms |
4216 KB |
Output is correct |
4 |
Correct |
13 ms |
4216 KB |
Output is correct |
5 |
Correct |
13 ms |
4216 KB |
Output is correct |
6 |
Correct |
12 ms |
4216 KB |
Output is correct |
7 |
Correct |
13 ms |
4344 KB |
Output is correct |
8 |
Correct |
12 ms |
4216 KB |
Output is correct |
9 |
Correct |
12 ms |
4216 KB |
Output is correct |
10 |
Correct |
12 ms |
4216 KB |
Output is correct |
11 |
Correct |
12 ms |
4344 KB |
Output is correct |
12 |
Correct |
13 ms |
4344 KB |
Output is correct |
13 |
Correct |
12 ms |
4216 KB |
Output is correct |
14 |
Correct |
13 ms |
4216 KB |
Output is correct |
15 |
Correct |
13 ms |
4216 KB |
Output is correct |
16 |
Correct |
8 ms |
2680 KB |
Output is correct |
17 |
Correct |
7 ms |
2680 KB |
Output is correct |
18 |
Correct |
8 ms |
2680 KB |
Output is correct |
19 |
Correct |
7 ms |
2680 KB |
Output is correct |
20 |
Correct |
7 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4216 KB |
Output is correct |
2 |
Correct |
12 ms |
4088 KB |
Output is correct |
3 |
Correct |
13 ms |
4216 KB |
Output is correct |
4 |
Correct |
13 ms |
4216 KB |
Output is correct |
5 |
Correct |
13 ms |
4216 KB |
Output is correct |
6 |
Correct |
12 ms |
4216 KB |
Output is correct |
7 |
Correct |
13 ms |
4344 KB |
Output is correct |
8 |
Correct |
12 ms |
4216 KB |
Output is correct |
9 |
Correct |
12 ms |
4216 KB |
Output is correct |
10 |
Correct |
12 ms |
4216 KB |
Output is correct |
11 |
Correct |
12 ms |
4344 KB |
Output is correct |
12 |
Correct |
13 ms |
4344 KB |
Output is correct |
13 |
Correct |
12 ms |
4216 KB |
Output is correct |
14 |
Correct |
13 ms |
4216 KB |
Output is correct |
15 |
Correct |
13 ms |
4216 KB |
Output is correct |
16 |
Correct |
8 ms |
2680 KB |
Output is correct |
17 |
Correct |
7 ms |
2680 KB |
Output is correct |
18 |
Correct |
8 ms |
2680 KB |
Output is correct |
19 |
Correct |
7 ms |
2680 KB |
Output is correct |
20 |
Correct |
7 ms |
2680 KB |
Output is correct |
21 |
Incorrect |
99 ms |
4216 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4216 KB |
Output is correct |
2 |
Correct |
12 ms |
4088 KB |
Output is correct |
3 |
Correct |
13 ms |
4216 KB |
Output is correct |
4 |
Correct |
13 ms |
4216 KB |
Output is correct |
5 |
Correct |
13 ms |
4216 KB |
Output is correct |
6 |
Correct |
12 ms |
4216 KB |
Output is correct |
7 |
Correct |
13 ms |
4344 KB |
Output is correct |
8 |
Correct |
12 ms |
4216 KB |
Output is correct |
9 |
Correct |
12 ms |
4216 KB |
Output is correct |
10 |
Correct |
12 ms |
4216 KB |
Output is correct |
11 |
Correct |
12 ms |
4344 KB |
Output is correct |
12 |
Correct |
13 ms |
4344 KB |
Output is correct |
13 |
Correct |
12 ms |
4216 KB |
Output is correct |
14 |
Correct |
13 ms |
4216 KB |
Output is correct |
15 |
Correct |
13 ms |
4216 KB |
Output is correct |
16 |
Correct |
8 ms |
2680 KB |
Output is correct |
17 |
Correct |
7 ms |
2680 KB |
Output is correct |
18 |
Correct |
8 ms |
2680 KB |
Output is correct |
19 |
Correct |
7 ms |
2680 KB |
Output is correct |
20 |
Correct |
7 ms |
2680 KB |
Output is correct |
21 |
Incorrect |
99 ms |
4216 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |