# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41592 | 2018-02-19T17:51:09 Z | gabrielsimoes | Boat (APIO16_boat) | C++14 | 7 ms | 388 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; const int MAXN = 510; ll fastpow(ll a, ll b) { ll result = 1; ll cur = a; while (b) { if (b & 1) result = (result * cur) % MOD; cur = (cur * cur) % MOD; b >>= 1; } return result; } int n; int va[MAXN], vb[MAXN]; vector<int> splits; vector<ll> dp, sum, v; ll inv[MAXN]; ll bin(ll a, ll b) { ll result = 1; while (a && b) result = (result + (a--) * inv[b--]); return result; } int main() { for (int i = 1; i < MAXN; i++) inv[i] = fastpow(i, MOD - 2); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d", &va[i], &vb[i]); vb[i]++; splits.push_back(va[i]); splits.push_back(vb[i]); } sort(splits.begin(), splits.end()); splits.resize(unique(splits.begin(), splits.end()) - splits.begin()); for (int i = 1; i <= n; i++) { va[i] = (lower_bound(splits.begin(), splits.end(), va[i]) - splits.begin()); vb[i] = (lower_bound(splits.begin(), splits.end(), vb[i]) - splits.begin()); } dp.resize(n); sum.resize(n); for (int split = 1; split < splits.size(); split++) { ll splitSize = splits[split] - splits[split - 1]; ll prevdpsum = 0; for (int i = 1; i <= n; i++) { if (va[i] < split && vb[i] >= split) { dp[i] = (dp[i] + splitSize + sum[i - 1] * splitSize) % MOD; for (auto p = v.rbegin(); p != v.rend(); p++) { int middle = p - v.rbegin(); dp[i] = (dp[i] + (*p) * bin(splitSize + middle + 1, middle + 2)) % MOD; } v.push_back(prevdpsum); } } for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + dp[i]; v.clear(); } ll ans = 0; for (int i = 1; i <= n; i++) ans = (ans + dp[i]) % MOD; printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 388 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 248 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |