This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<stdint.h>
#define int int64_t
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(int i=(j);i<(k);++i)
#define RREP(i,j,k) for(int i=(j)-1;i>=(k);--i)
#define MST(a,v) memset(a,(v),sizeof a)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define F first
#define S second
#define IOS cin.tie(0),ios_base::sync_with_stdio(false)
#define add(x,y) x=(x+y)%mo
const int maxn=509,mo=1e9L+7;
int n,a[maxn],b[maxn],dp[maxn],inv[maxn];
vector<int>p;
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;
}
main(){
IOS;
cin>>n;
REP(i,1,n+1)inv[i]=qp(i,mo-2);
REP(i,0,n)cin>>a[i]>>b[i],++b[i],p.pb(a[i]),p.pb(b[i]);
sort(ALL(p));
p.resize(unique(ALL(p))-p.begin());
REP(i,0,n)a[i]=find(ALL(p),a[i])-p.begin(),b[i]=find(ALL(p),b[i])-p.begin();
dp[0]=1;
REP(i,0,p.size()-1){
int l=p[i+1]-p[i];
RREP(j,n,0){
if(a[j]<=i&&i<b[j]){
int c=l,t=1;
RREP(k,j+1,0){
add(dp[j+1],c*dp[k]%mo);
if(k&&a[k-1]<=i&&i<b[k-1])c=c*(t+l)%mo*inv[t+1]%mo,++t;
}
}
}
}
int sum=0;
REP(i,0,n)add(sum,dp[i+1]);
cout<<sum<<endl;
}
Compilation message (stderr)
boat.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
boat.cpp: In function 'int main()':
boat.cpp:6:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define REP(i,j,k) for(int i=(j);i<(k);++i)
^
boat.cpp:38:2: note: in expansion of macro 'REP'
REP(i,0,p.size()-1){
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |