Submission #447785

#TimeUsernameProblemLanguageResultExecution timeMemory
447785dutchBoat (APIO16_boat)C++17
0 / 100
15 ms8208 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define valid(x, y) (a[x] <= pts[y] && pts[y+1] <= b[x]+1) 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*2][LIM]; vector<int> pts; 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 i=0; i<m; ++i){ int diff = pts[i+1] - pts[i]; int p = 1; for(int j=1; j<=n; ++j){ (p *= diff - j + 1) %= MOD; C[i][j] = (p * invF[j]) % MOD; } } for(int i=0; i<n; ++i){ for(int k=0; k<m; ++k){ if(!valid(i, k)) continue; int cnt = 1, p = C[k][1]; for(int j=i; --j>=0; ){ if(k) (dp[i][k] += dp[j][k-1] * cnt) %= MOD; if(valid(j, k)) p += C[k][++cnt]; } (dp[i][k] += p) %= MOD; (ans += dp[i][k]) %= MOD; } for(int k=1; k<m; ++k) (dp[i][k] += dp[i][k-1]) %= MOD; } 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...