Submission #47645

#TimeUsernameProblemLanguageResultExecution timeMemory
47645square1001Boat (APIO16_boat)C++14
9 / 100
281 ms4588 KiB
#include <iostream> #include <algorithm> using namespace std; const int mod = 1000000007; int n, c, a[509], b[509], x[1009], inv[509], comb[1009][509], dp[509][1009]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; x[i] = a[i]; x[i + n] = ++b[i]; } sort(x, x + 2 * n); c = unique(x, x + 2 * n) - x; for (int i = 0; i < n; ++i) { a[i] = lower_bound(x, x + c, a[i]) - x; b[i] = lower_bound(x, x + c, b[i]) - x; } inv[1] = 1; for (int i = 2; i <= n; ++i) { inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod; } for (int i = 0; i < c - 1; ++i) { int way = 1; for (int j = 1; j <= n; ++j) { way = 1LL * way * (x[i + 1] - x[i] - j + 1) % mod * inv[j] % mod; comb[i][j] = comb[i][j - 1] + way; if (comb[i][j] >= mod) comb[i][j] -= mod; } } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = a[i]; j < b[i]; ++j) { int num = 0; for (int k = i - 1; k >= 0; --k) { if (a[k + 1] <= j && j < b[k + 1]) ++num; dp[i][j + 1] = (dp[i][j + 1] + 1LL * comb[j][num] * dp[k][j]) % mod; } if (a[0] <= j && j < b[0]) ++num; dp[i][j + 1] += comb[j][num]; if (dp[i][j + 1] >= mod) dp[i][j + 1] -= mod; } for (int j = 0; j < c; ++j) { dp[i][j + 1] += dp[i][j]; if (dp[i][j + 1] >= mod) dp[i][j + 1] -= mod; } ans += dp[i][c]; if (ans >= mod) ans -= mod; } 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...