# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
315987 | 2020-10-24T17:00:30 Z | phathnv | Boat (APIO16_boat) | C++11 | 540 ms | 4224 KB |
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "Boat" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 502; const int MOD = 1e9 + 7; int n, a[N], b[N]; int nX, x[2 * N], inv[N], dp[2][N * 2][N]; void readInput(){ cin >> n; for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; } void compress(){ for(int i = 1; i <= n; i++){ x[++nX] = a[i]; x[++nX] = ++b[i]; } sort(x + 1, x + 1 + nX); nX = unique(x + 1, x + 1 + nX) - (x + 1); for(int i = 1; i <= n; i++){ a[i] = lower_bound(x + 1, x + 1 + nX, a[i]) - x; b[i] = lower_bound(x + 1, x + 1 + nX, b[i]) - x; } } int powMod(int x, int k){ if (k == 0) return 1; int res = powMod(x, k >> 1); res = (ll) res * res % MOD; if (k & 1) res = (ll) res * x % MOD; return res; } void prepare(){ for(int i = 1; i <= n; i++) b[i]--; inv[0] = 1; for(int i = 1; i <= n; i++) inv[i] = powMod(i, MOD - 2); } void add(int &x, int y){ x += y; x -= (x >= MOD) * MOD; } void solve(){ int res = 0; for(int i = 0; i < n; i++){ int id = i & 1; for(int j = 1; j < nX; j++){ int len = min(n, x[j + 1] - x[j]); for(int k = 1; k <= len; k++) dp[id ^ 1][j][k] = 0; } int sum = 1; for(int j = 1; j < nX; j++){ int len = min(n, x[j + 1] - x[j]); if (a[i + 1] <= j && j <= b[i + 1]) add(dp[id ^ 1][j][1], (ll) sum * len % MOD); for(int k = 1; k <= len; k++){ add(sum, dp[id][j][k]); if (a[i + 1] <= j && j <= b[i + 1] && k < len) add(dp[id ^ 1][j][k + 1], (ll) dp[id][j][k] * (len - k) % MOD * inv[k + 1] % MOD); } } for(int j = 1; j < nX; j++){ int len = min(n, x[j + 1] - x[j]); for(int k = 1; k <= len; k++) add(res, dp[id ^ 1][j][k]); } } cout << res; } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } readInput(); compress(); prepare(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 540 ms | 4224 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 540 ms | 4224 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 1152 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 540 ms | 4224 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |