Submission #758709

#TimeUsernameProblemLanguageResultExecution timeMemory
758709Trisanu_DasBoat (APIO16_boat)C++17
100 / 100
657 ms4404 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int mod=1e9+7; int dp[1005][505], inv[505], a[505], b[505], c[1005]; set<int> s; int f(int x, int y) { if (!y) return 1; int res=f(x, y/2); if (y&1) return res*res%mod*x%mod; else return res*res%mod; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m=0; cin >> n; for (int i=1; i<=n; i++) inv[i]=f(i, mod-2); for (int i=1; i<=n; i++) { cin >> a[i] >> b[i]; s.insert(a[i]); s.insert(b[i]+1); } for (auto itr=s.begin(); itr!=s.end(); itr++) c[++m]=(*itr); for (int i=0; i<=n; i++) dp[0][i]=1; for (int i=1; i<m; i++) { for (int j=0; j<=n; j++) { dp[i][j]=dp[i-1][j]; int num=1, cnt=0; for (int k=1; k<=j; k++) { if (a[j-k+1]<=c[i] && c[i+1]-1<=b[j-k+1]) { cnt++; num=num*(c[i+1]-c[i]+cnt-1)%mod*inv[cnt]%mod; dp[i][j]=(dp[i][j]+dp[i-1][j-k]*num)%mod; } } } } cout << dp[m-1][n]-1; 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...