Submission #142986

#TimeUsernameProblemLanguageResultExecution timeMemory
142986IC_COLDSTOPBoat (APIO16_boat)C++17
100 / 100
696 ms12536 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define int ll #define MP make_pair #define pb push_back #define F first #define S second #define pii pair<int,int> #define REP(i,a,b) for(int i=a; i<b; i++) const int MX=5e2+3, mod=1e9+7; int n, m, dp[10][MX*2][2*MX], l[MX], r[MX], num[2*MX], p[MX*2]; map<int,int> mark; vector<int> vec; int pw(int a, int b){ if(!b) return 1; int nsf=pw(a,b/2); nsf=nsf*nsf%mod; if(b&1) nsf*=a; return nsf%mod; } int32_t main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); REP(i,1,MX*2) p[i]=pw(i,mod-2); cin>>n; REP(i,0,n){ cin>>l[i]>>r[i]; r[i]++; if(!mark[l[i]]) mark[l[i]]=1, vec.pb(l[i]); if(!mark[r[i]]) mark[r[i]]=1, vec.pb(r[i]); } m=vec.size(); //cout<<m<<endl; sort(vec.begin(), vec.end()); int mm=0; dp[mm][0][0]=1; REP(j,1,m){ dp[mm][j][0]=dp[mm][j-1][0]+dp[mm][j-1][1]; if(l[0]<vec[j] && r[0]>=vec[j]) dp[mm][j][1]=(vec[j]-vec[j-1])%mod, num[j]++; // cout<<j<<" "<<dp[mm][j][0]<<" "<<dp[mm][j][1]<<" "<<vec[j]<<" "<<vec[j-1]<<endl; } REP(i,1,n){ mm^=1; REP(j,1,m){ dp[mm][j][0]=0; if(j>1) REP(w,0,num[j-1]+1){ dp[mm][j][0]=(dp[mm][j-1][w]+dp[mm][j][0])%mod; // if(i==2 && j==2) cout<<" B "<<dp[mm][j][0]<<" "<<dp[mm][j-1][w]<<endl; } else dp[mm][j][0]=1; int flg=0, cnt=vec[j]-vec[j-1]; if(l[i]<vec[j] && r[i]>=vec[j]) flg=1, num[j]++; REP(w,1,num[j]+1){ dp[mm][j][w]=dp[mm^1][j][w]; if(flg){ dp[mm][j][w]=((ll)dp[mm][j][w] + (ll)dp[mm^1][j][w-1] * (cnt-w+1) %mod * p[w]%mod )%mod; } } //cout<<i<<" "<<j<<" "<<flg<<" "<<num[j]<<endl; } } //cout<<endl; int sum=0; REP(w,0,MX*2){ sum=(sum+dp[mm][m-1][w])%mod; //cout<<w<<" "<<dp[mm][m-1][w]<<" "<<dp[mm][m-2][w]<<" "<<dp[mm][m-3][w]<<" "<<dp[mm^1][m-1][w]<<" "<<dp[mm^1][m-2][w]<<" "<<dp[mm^1][m-3][w]<<endl; } cout<<sum-1<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...