Submission #1032691

#TimeUsernameProblemLanguageResultExecution timeMemory
1032691KerimBoat (APIO16_boat)C++17
100 / 100
1186 ms1916 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(v) (int)(v).size() const int md = (int)1e9 + 7; const int N = 505; vector<int> fct(N), inv(N), inv_fct(N); 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; for (int i = 1; i <= r; i++) x = (ll)x * (n - r + i) % md; return (ll)x * inv_fct[r] % md; } int rdp[N][N], p[N]; int rec(int x, int y, vector<int>&v){ if (x < 0) return 0; if (y == 1) return (rec(x-1, y, v) + p[v[x] - 1]) % md; int &ret = rdp[x][y]; if (~ret) return ret; return ret = (rec(x-1, y, v) + rec(x-1, y-1, v)) % md; } int main() { // freopen("file.in", "r", stdin); ios::sync_with_stdio(false); cin.tie(nullptr); fct[0] = inv[0] = inv_fct[0] = 1; for (int i = 1; i < N; i++) { inv[i] = pw(i, md - 2); fct[i] = (ll)fct[i - 1] * i % md; inv_fct[i] = pw(fct[i], md - 2); } 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 < sz(mv); 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; vector<int> c(sz(v)); for (int j = 1; j < c.size(); j++) c[j] = C(R, j + 1); memset(rdp, -1, sizeof rdp); p[0] = 1; for (int j = 1; j <= n; j++) p[j] = (p[j - 1] + dp[j]) % md; for (int i = 0; i < sz(v); i++) { nw_dp[v[i]] = (dp[v[i]] + (ll)p[v[i] - 1] * R % md) % md; for (int j = 1; j <= min(i, R - 1); j++) { nw_dp[v[i]] = (nw_dp[v[i]] + (ll)rec(i-1, j, v) * c[j] % md) % md; // x = (ll)fct[j - 1] * inv_fct[j - 1] % md; // for (int k = i - j; k >= 0; k--) { // if (k != i - j) x = ((ll)x * (i - k - 1) % md) * inv[i - k - j] % md; // nw_dp[v[i]] = (nw_dp[v[i]] + ((ll)p[v[k] - 1] * x % md) * c % md) % md; // } } } dp = nw_dp; } int sm = 0; for (auto i : dp) sm = (sm + i) % md; cout << sm << '\n'; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:81:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for (int j = 1; j < c.size(); j++)
      |                         ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...