Submission #447811

#TimeUsernameProblemLanguageResultExecution timeMemory
447811dutchBoat (APIO16_boat)C++17
9 / 100
2090 ms4412 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9+7, LIM = 501; int modInverse(int x){ int r = 1, p = (MOD - 2) * 2; for(int y=x; p/=2; y=(y*y) % MOD) if(p & 1) r = (r*y) % MOD; return r; } int n, a[LIM], b[LIM], dp[LIM][LIM*2], F[LIM], invF[LIM], C[LIM]; bool valid[LIM]; vector<int> pts; int nCr(int x, int y){ return (((F[x] * invF[y]) % MOD) * invF[x-y]) % MOD; } void add(int &x, int y){ x += y; while(x >= MOD) x -= MOD; while(x <=-MOD) x += MOD; } signed main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i=0; i<n; ++i){ cin >> a[i] >> b[i]; pts.push_back(a[i]); pts.push_back(b[i]+1); } sort(pts.begin(), pts.end()); pts.resize(unique(pts.begin(), pts.end()) - pts.begin()); int m = size(pts) - 1, ans = 0; F[0] = invF[0] = 1; for(int i=1; i<=n; ++i){ F[i] = (F[i-1] * i) % MOD; invF[i] = modInverse(F[i]); } for(int k=0; k<m; ++k){ for(int i=1; i<=n; ++i){ int p = 1; C[i] = 0; for(int j=1; j<=i; ++j){ (p *= pts[k+1] - pts[k] - j + 1) %= MOD; (C[i] += ((p * invF[j]) % MOD) * nCr(i-1, j-1)) %= MOD; } } for(int i=0; i<n; ++i){ valid[i] = a[i] <= pts[k] && pts[k+1] <= b[i]+1; } for(int i=0; i<n; ++i){ if(valid[i]){ int cnt = 1; for(int j=i; --j>=0; ){ if(k) add(dp[i][k], dp[j][k-1] * C[cnt]); cnt += valid[j]; } add(dp[i][k], C[cnt]); add(ans, dp[i][k]); } if(k){ add(dp[i][k], dp[i][k-1]); } } } cout << (ans % MOD + MOD) % MOD; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...