# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
107318 |
2019-04-23T09:36:28 Z |
username |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
4480 KB |
#include<bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(register int i=(j);i<(k);++i)
#define RREP(i,j,k) for(register int i=(j)-1;i>=(k);--i)
#define ALL(a) a.begin(),a.end()
#define MST(a,v) memset(a,(v),sizeof a)
#define F first
#define S second
#define endl '\n'
#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
const int maxn=509,mo=1e9L+7;
int n,q=0,a[maxn],b[maxn],dp[2*maxn][maxn];
pii p[2*maxn];
int qp(int x,int t){
int re=1;
while(t){
if(t&1)re=re*x%mo;
x=x*x%mo,t>>=1;
}
return re;
}
void add(int&x,int y){
x=(x+y);
if(x>=mo)x-=mo;
}
main(){
IOS;
cin>>n;
REP(i,0,n)cin>>a[i]>>b[i],++b[i],p[q++]=pii(a[i],0),p[q++]=pii(b[i],0);
sort(p,p+q);
q=unique(p,p+q)-p;
REP(i,0,q)p[i].S=i;
REP(i,0,n)a[i]=lower_bound(p,p+q,pii(a[i],0))->S,b[i]=lower_bound(p,p+q,pii(b[i],0))->S;
MST(dp[0],0);
dp[0][0]=1;
REP(i,0,q-1){
dp[i+1][0]=dp[i][0];
REP(j,0,n){
dp[i+1][j+1]=0;
int l=p[i+1].F-p[i].F;
add(dp[i+1][j+1],dp[i][j+1]);
if(a[j]<=i&&i<b[j]){
int c=l,t=1;
RREP(k,j+1,0){
add(dp[i+1][j+1],dp[i][k]*c%mo);
if(k&&a[k-1]<=i&&i<b[k-1])c=c*(k+l)%mo*qp(k+1,mo-2)%mo,++t;
}
}
}
}
int sum=0;
REP(i,0,n)add(sum,dp[q-1][i+1]);
cout<<sum<<endl;
}
Compilation message
boat.cpp:32:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4352 KB |
Output is correct |
2 |
Correct |
7 ms |
4480 KB |
Output is correct |
3 |
Correct |
7 ms |
4352 KB |
Output is correct |
4 |
Correct |
8 ms |
4352 KB |
Output is correct |
5 |
Correct |
8 ms |
4352 KB |
Output is correct |
6 |
Correct |
7 ms |
4352 KB |
Output is correct |
7 |
Correct |
6 ms |
4352 KB |
Output is correct |
8 |
Correct |
6 ms |
4352 KB |
Output is correct |
9 |
Correct |
7 ms |
4352 KB |
Output is correct |
10 |
Correct |
7 ms |
4352 KB |
Output is correct |
11 |
Correct |
7 ms |
4352 KB |
Output is correct |
12 |
Correct |
6 ms |
4352 KB |
Output is correct |
13 |
Correct |
7 ms |
4352 KB |
Output is correct |
14 |
Correct |
7 ms |
4352 KB |
Output is correct |
15 |
Correct |
8 ms |
4352 KB |
Output is correct |
16 |
Correct |
5 ms |
1124 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
4 ms |
1152 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4352 KB |
Output is correct |
2 |
Correct |
7 ms |
4480 KB |
Output is correct |
3 |
Correct |
7 ms |
4352 KB |
Output is correct |
4 |
Correct |
8 ms |
4352 KB |
Output is correct |
5 |
Correct |
8 ms |
4352 KB |
Output is correct |
6 |
Correct |
7 ms |
4352 KB |
Output is correct |
7 |
Correct |
6 ms |
4352 KB |
Output is correct |
8 |
Correct |
6 ms |
4352 KB |
Output is correct |
9 |
Correct |
7 ms |
4352 KB |
Output is correct |
10 |
Correct |
7 ms |
4352 KB |
Output is correct |
11 |
Correct |
7 ms |
4352 KB |
Output is correct |
12 |
Correct |
6 ms |
4352 KB |
Output is correct |
13 |
Correct |
7 ms |
4352 KB |
Output is correct |
14 |
Correct |
7 ms |
4352 KB |
Output is correct |
15 |
Correct |
8 ms |
4352 KB |
Output is correct |
16 |
Correct |
5 ms |
1124 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
4 ms |
1152 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Execution timed out |
2053 ms |
2892 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
1144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4352 KB |
Output is correct |
2 |
Correct |
7 ms |
4480 KB |
Output is correct |
3 |
Correct |
7 ms |
4352 KB |
Output is correct |
4 |
Correct |
8 ms |
4352 KB |
Output is correct |
5 |
Correct |
8 ms |
4352 KB |
Output is correct |
6 |
Correct |
7 ms |
4352 KB |
Output is correct |
7 |
Correct |
6 ms |
4352 KB |
Output is correct |
8 |
Correct |
6 ms |
4352 KB |
Output is correct |
9 |
Correct |
7 ms |
4352 KB |
Output is correct |
10 |
Correct |
7 ms |
4352 KB |
Output is correct |
11 |
Correct |
7 ms |
4352 KB |
Output is correct |
12 |
Correct |
6 ms |
4352 KB |
Output is correct |
13 |
Correct |
7 ms |
4352 KB |
Output is correct |
14 |
Correct |
7 ms |
4352 KB |
Output is correct |
15 |
Correct |
8 ms |
4352 KB |
Output is correct |
16 |
Correct |
5 ms |
1124 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
4 ms |
1152 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Execution timed out |
2053 ms |
2892 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |