Submission #886029

#TimeUsernameProblemLanguageResultExecution timeMemory
886029NeroZeinBoat (APIO16_boat)C++17
27 / 100
5 ms1372 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif const int md = (int) 1e9 + 7; const int N = 503; int iv[N]; int len[N]; int dp[N][N]; long long a[N], b[N]; void add(int& x, int y) { x += y; if (x >= md) x -= md; } int mul(int x, int y) { return (int) ((long long) x * y % md); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<long long> c; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; c.push_back(a[i]); c.push_back(++b[i]); } sort(c.begin(), c.end()); c.resize(unique(c.begin(), c.end()) - c.begin()); for (int i = 1; i <= n; ++i) { a[i] = upper_bound(c.begin(), c.end(), a[i]) - c.begin(); b[i] = upper_bound(c.begin(), c.end(), b[i]) - c.begin(); } iv[1] = 1; for (int i = 2; i <= n; ++i) { iv[i] = mul(md - md / i, iv[md % i]); } int m = (int) c.size(); for (int i = 1; i < m; ++i) { len[i] = c[i] - c[i - 1]; } for (int i = 0; i <= m; ++i) { dp[0][i] = 1; } for (int i = 1; i <= n; ++i) { for (int j = a[i]; j < b[i]; ++j) { int prod = len[j], cnt = 1; for (int k = i - 1; k >= 0; --k) { add(dp[i][j], mul(dp[k][j - 1], prod)); if (a[k] <= j && j < b[k]) { prod = mul(prod, iv[cnt + 1]); prod = mul(prod, len[j] + cnt); cnt++; } } } for (int j = 1; j <= m; ++j) { add(dp[i][j], dp[i][j - 1]); } } int ans = 0; for (int i = 1; i <= n; ++i) { add(ans, dp[i][m]); } cout << ans << '\n'; 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...