# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
41608 | 2018-02-19T19:33:47 Z | gabrielsimoes | Boat (APIO16_boat) | C++14 | 13 ms | 620 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]; ll dp[MAXN], sum[MAXN]; vector<int> splits; vector<ll> v; ll inv[MAXN], bin[MAXN]; 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()); } for (int split = 1; split < splits.size(); split++) { ll splitSize = splits[split] - splits[split - 1]; sum[0] = 1; for (int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + dp[i]) % MOD; v.clear(); bin[0] = 1; for (int i = 2; i <= n; i++) { bin[i] = ((((splitSize + i - 2) * inv[i]) % MOD) * bin[i - 1]) % MOD; } bin[1] = splitSize; for (int i = 1; i <= n; i++) { if (va[i] < split && vb[i] >= split) { v.push_back(sum[i - 1]); for (auto p = v.rbegin(); p != v.rend(); p++) { int cnt = (p - v.rbegin()) + 1; dp[i] = (dp[i] + (*p) * bin[cnt]) % MOD; } } // printf("dp[%d][%d] == %lld\n", split, i, dp[i]); } } ll ans = 0; for (int i = 1; i <= n; i++) ans = (ans + dp[i]) % MOD; printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 248 KB | Output is correct |
2 | Correct | 10 ms | 352 KB | Output is correct |
3 | Correct | 11 ms | 424 KB | Output is correct |
4 | Correct | 10 ms | 444 KB | Output is correct |
5 | Correct | 11 ms | 444 KB | Output is correct |
6 | Correct | 10 ms | 504 KB | Output is correct |
7 | Correct | 10 ms | 620 KB | Output is correct |
8 | Correct | 9 ms | 620 KB | Output is correct |
9 | Correct | 10 ms | 620 KB | Output is correct |
10 | Correct | 10 ms | 620 KB | Output is correct |
11 | Correct | 10 ms | 620 KB | Output is correct |
12 | Correct | 9 ms | 620 KB | Output is correct |
13 | Correct | 9 ms | 620 KB | Output is correct |
14 | Correct | 9 ms | 620 KB | Output is correct |
15 | Correct | 9 ms | 620 KB | Output is correct |
16 | Incorrect | 3 ms | 620 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 248 KB | Output is correct |
2 | Correct | 10 ms | 352 KB | Output is correct |
3 | Correct | 11 ms | 424 KB | Output is correct |
4 | Correct | 10 ms | 444 KB | Output is correct |
5 | Correct | 11 ms | 444 KB | Output is correct |
6 | Correct | 10 ms | 504 KB | Output is correct |
7 | Correct | 10 ms | 620 KB | Output is correct |
8 | Correct | 9 ms | 620 KB | Output is correct |
9 | Correct | 10 ms | 620 KB | Output is correct |
10 | Correct | 10 ms | 620 KB | Output is correct |
11 | Correct | 10 ms | 620 KB | Output is correct |
12 | Correct | 9 ms | 620 KB | Output is correct |
13 | Correct | 9 ms | 620 KB | Output is correct |
14 | Correct | 9 ms | 620 KB | Output is correct |
15 | Correct | 9 ms | 620 KB | Output is correct |
16 | Incorrect | 3 ms | 620 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 620 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 248 KB | Output is correct |
2 | Correct | 10 ms | 352 KB | Output is correct |
3 | Correct | 11 ms | 424 KB | Output is correct |
4 | Correct | 10 ms | 444 KB | Output is correct |
5 | Correct | 11 ms | 444 KB | Output is correct |
6 | Correct | 10 ms | 504 KB | Output is correct |
7 | Correct | 10 ms | 620 KB | Output is correct |
8 | Correct | 9 ms | 620 KB | Output is correct |
9 | Correct | 10 ms | 620 KB | Output is correct |
10 | Correct | 10 ms | 620 KB | Output is correct |
11 | Correct | 10 ms | 620 KB | Output is correct |
12 | Correct | 9 ms | 620 KB | Output is correct |
13 | Correct | 9 ms | 620 KB | Output is correct |
14 | Correct | 9 ms | 620 KB | Output is correct |
15 | Correct | 9 ms | 620 KB | Output is correct |
16 | Incorrect | 3 ms | 620 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |