Submission #1031141

#TimeUsernameProblemLanguageResultExecution timeMemory
1031141stdfloatBoat (APIO16_boat)C++17
9 / 100
2056 ms592 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int md = (int)1e9 + 7; int pw(int x, int y) { int res = 1; while (y) { if (y & 1) res = (ll)res * x % md; x = (ll)x * x % md; y >>= 1; } return res; } int C(int n, int r) { int x = 1, y = 1; for (int i = 1; i <= r; i++) { x = (ll)x * (n - r + i) % md; y = (ll)y * i % md; } return (ll)x * pw(y, md - 2) % md; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; map<int, vector<int>> m; vector<int> a(n + 1), b(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; m[a[i]].push_back(i); m[b[i] + 1].push_back(-i); } vector<int> mv; for (auto i : m) mv.push_back(i.first); set<int> s; vector<int> dp(n + 1); for (int ii = 0; ii + 1 < (int)mv.size(); ii++) { for (auto j : m[mv[ii]]) { if (0 < j) s.insert(j); else s.erase(-j); } int R = mv[ii + 1] - mv[ii]; vector<int> v(s.begin(), s.end()), nw_dp = dp; for (int i = 0; i < (int)v.size(); i++) { int sm = 1; for (int j = 1; j < v[i]; j++) sm = (sm + dp[j]) % md; nw_dp[v[i]] = (dp[v[i]] + (ll)sm * R % md) % md; for (int j = 1; j <= min(i, R - 1); j++) { int c = C(R, j + 1), sm = 1; for (int k = 1; k <= v[i - j]; k++) sm = (sm + dp[k]) % md; for (int k = i - j; k >= 0; k--) { int sm = 1; for (int l = 1; l < v[k]; l++) sm = (sm + dp[l]) % md; nw_dp[v[i]] = (nw_dp[v[i]] + ((ll)sm * C(i - k - 1, j - 1) % md) * c % md) % md; } } } dp = nw_dp; } int sm = 0; for (auto i : dp) sm = (sm + i) % md; cout << sm << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...