# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
41681 | 2018-02-20T12:33:14 Z | gabrielsimoes | Boat (APIO16_boat) | C++14 | 182 ms | 768 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; const int MAXN = 510; inline ll mod(ll a) { return a %= MOD, a < 0 ? a + MOD : a; } int n, va[MAXN], vb[MAXN]; vector<int> splits; ll dp[MAXN], sum[MAXN]; ll inv[MAXN], bin[MAXN]; vector<ll> v; int main() { inv[1] = 1; for (int i = 2; i < MAXN; i++) inv[i] = mod(-(MOD / i) * inv[MOD % i]); 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 len = 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 = 1; i <= n; i++) { if (i <= len + i - 2) bin[i] = mod(mod((len + i - 2) * inv[i]) * bin[i - 1]); else bin[i] = 0; } 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; if (cnt == 1) dp[i] += mod((*p) * len); else dp[i] += mod((*p) * bin[cnt]); } dp[i] %= MOD; } } } ll ans = 0; for (int i = 1; i <= n; i++) ans += dp[i]; printf("%lld\n", ans % MOD); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 248 KB | Output is correct |
2 | Correct | 9 ms | 352 KB | Output is correct |
3 | Correct | 9 ms | 552 KB | Output is correct |
4 | Correct | 9 ms | 552 KB | Output is correct |
5 | Correct | 9 ms | 552 KB | Output is correct |
6 | Correct | 8 ms | 580 KB | Output is correct |
7 | Correct | 7 ms | 580 KB | Output is correct |
8 | Correct | 9 ms | 584 KB | Output is correct |
9 | Correct | 8 ms | 608 KB | Output is correct |
10 | Correct | 8 ms | 608 KB | Output is correct |
11 | Correct | 8 ms | 608 KB | Output is correct |
12 | Correct | 8 ms | 620 KB | Output is correct |
13 | Correct | 8 ms | 748 KB | Output is correct |
14 | Correct | 8 ms | 748 KB | Output is correct |
15 | Correct | 7 ms | 748 KB | Output is correct |
16 | Correct | 3 ms | 748 KB | Output is correct |
17 | Correct | 3 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 3 ms | 748 KB | Output is correct |
20 | Correct | 3 ms | 748 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 248 KB | Output is correct |
2 | Correct | 9 ms | 352 KB | Output is correct |
3 | Correct | 9 ms | 552 KB | Output is correct |
4 | Correct | 9 ms | 552 KB | Output is correct |
5 | Correct | 9 ms | 552 KB | Output is correct |
6 | Correct | 8 ms | 580 KB | Output is correct |
7 | Correct | 7 ms | 580 KB | Output is correct |
8 | Correct | 9 ms | 584 KB | Output is correct |
9 | Correct | 8 ms | 608 KB | Output is correct |
10 | Correct | 8 ms | 608 KB | Output is correct |
11 | Correct | 8 ms | 608 KB | Output is correct |
12 | Correct | 8 ms | 620 KB | Output is correct |
13 | Correct | 8 ms | 748 KB | Output is correct |
14 | Correct | 8 ms | 748 KB | Output is correct |
15 | Correct | 7 ms | 748 KB | Output is correct |
16 | Correct | 3 ms | 748 KB | Output is correct |
17 | Correct | 3 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 3 ms | 748 KB | Output is correct |
20 | Correct | 3 ms | 748 KB | Output is correct |
21 | Correct | 79 ms | 748 KB | Output is correct |
22 | Correct | 79 ms | 748 KB | Output is correct |
23 | Correct | 67 ms | 748 KB | Output is correct |
24 | Correct | 74 ms | 748 KB | Output is correct |
25 | Correct | 72 ms | 748 KB | Output is correct |
26 | Correct | 157 ms | 748 KB | Output is correct |
27 | Correct | 155 ms | 748 KB | Output is correct |
28 | Correct | 153 ms | 748 KB | Output is correct |
29 | Correct | 152 ms | 748 KB | Output is correct |
30 | Correct | 10 ms | 748 KB | Output is correct |
31 | Correct | 10 ms | 748 KB | Output is correct |
32 | Correct | 9 ms | 748 KB | Output is correct |
33 | Correct | 10 ms | 748 KB | Output is correct |
34 | Correct | 10 ms | 748 KB | Output is correct |
35 | Correct | 9 ms | 748 KB | Output is correct |
36 | Correct | 9 ms | 748 KB | Output is correct |
37 | Correct | 9 ms | 748 KB | Output is correct |
38 | Correct | 9 ms | 748 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 748 KB | Output is correct |
2 | Correct | 3 ms | 748 KB | Output is correct |
3 | Correct | 3 ms | 748 KB | Output is correct |
4 | Correct | 7 ms | 748 KB | Output is correct |
5 | Correct | 3 ms | 748 KB | Output is correct |
6 | Correct | 4 ms | 748 KB | Output is correct |
7 | Correct | 3 ms | 768 KB | Output is correct |
8 | Correct | 4 ms | 768 KB | Output is correct |
9 | Correct | 3 ms | 768 KB | Output is correct |
10 | Correct | 4 ms | 768 KB | Output is correct |
11 | Correct | 3 ms | 768 KB | Output is correct |
12 | Correct | 2 ms | 768 KB | Output is correct |
13 | Correct | 4 ms | 768 KB | Output is correct |
14 | Correct | 2 ms | 768 KB | Output is correct |
15 | Correct | 3 ms | 768 KB | Output is correct |
16 | Correct | 2 ms | 768 KB | Output is correct |
17 | Correct | 2 ms | 768 KB | Output is correct |
18 | Correct | 2 ms | 768 KB | Output is correct |
19 | Correct | 2 ms | 768 KB | Output is correct |
20 | Correct | 2 ms | 768 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 248 KB | Output is correct |
2 | Correct | 9 ms | 352 KB | Output is correct |
3 | Correct | 9 ms | 552 KB | Output is correct |
4 | Correct | 9 ms | 552 KB | Output is correct |
5 | Correct | 9 ms | 552 KB | Output is correct |
6 | Correct | 8 ms | 580 KB | Output is correct |
7 | Correct | 7 ms | 580 KB | Output is correct |
8 | Correct | 9 ms | 584 KB | Output is correct |
9 | Correct | 8 ms | 608 KB | Output is correct |
10 | Correct | 8 ms | 608 KB | Output is correct |
11 | Correct | 8 ms | 608 KB | Output is correct |
12 | Correct | 8 ms | 620 KB | Output is correct |
13 | Correct | 8 ms | 748 KB | Output is correct |
14 | Correct | 8 ms | 748 KB | Output is correct |
15 | Correct | 7 ms | 748 KB | Output is correct |
16 | Correct | 3 ms | 748 KB | Output is correct |
17 | Correct | 3 ms | 748 KB | Output is correct |
18 | Correct | 3 ms | 748 KB | Output is correct |
19 | Correct | 3 ms | 748 KB | Output is correct |
20 | Correct | 3 ms | 748 KB | Output is correct |
21 | Correct | 79 ms | 748 KB | Output is correct |
22 | Correct | 79 ms | 748 KB | Output is correct |
23 | Correct | 67 ms | 748 KB | Output is correct |
24 | Correct | 74 ms | 748 KB | Output is correct |
25 | Correct | 72 ms | 748 KB | Output is correct |
26 | Correct | 157 ms | 748 KB | Output is correct |
27 | Correct | 155 ms | 748 KB | Output is correct |
28 | Correct | 153 ms | 748 KB | Output is correct |
29 | Correct | 152 ms | 748 KB | Output is correct |
30 | Correct | 10 ms | 748 KB | Output is correct |
31 | Correct | 10 ms | 748 KB | Output is correct |
32 | Correct | 9 ms | 748 KB | Output is correct |
33 | Correct | 10 ms | 748 KB | Output is correct |
34 | Correct | 10 ms | 748 KB | Output is correct |
35 | Correct | 9 ms | 748 KB | Output is correct |
36 | Correct | 9 ms | 748 KB | Output is correct |
37 | Correct | 9 ms | 748 KB | Output is correct |
38 | Correct | 9 ms | 748 KB | Output is correct |
39 | Correct | 3 ms | 748 KB | Output is correct |
40 | Correct | 3 ms | 748 KB | Output is correct |
41 | Correct | 3 ms | 748 KB | Output is correct |
42 | Correct | 7 ms | 748 KB | Output is correct |
43 | Correct | 3 ms | 748 KB | Output is correct |
44 | Correct | 4 ms | 748 KB | Output is correct |
45 | Correct | 3 ms | 768 KB | Output is correct |
46 | Correct | 4 ms | 768 KB | Output is correct |
47 | Correct | 3 ms | 768 KB | Output is correct |
48 | Correct | 4 ms | 768 KB | Output is correct |
49 | Correct | 3 ms | 768 KB | Output is correct |
50 | Correct | 2 ms | 768 KB | Output is correct |
51 | Correct | 4 ms | 768 KB | Output is correct |
52 | Correct | 2 ms | 768 KB | Output is correct |
53 | Correct | 3 ms | 768 KB | Output is correct |
54 | Correct | 2 ms | 768 KB | Output is correct |
55 | Correct | 2 ms | 768 KB | Output is correct |
56 | Correct | 2 ms | 768 KB | Output is correct |
57 | Correct | 2 ms | 768 KB | Output is correct |
58 | Correct | 2 ms | 768 KB | Output is correct |
59 | Correct | 104 ms | 768 KB | Output is correct |
60 | Correct | 76 ms | 768 KB | Output is correct |
61 | Correct | 77 ms | 768 KB | Output is correct |
62 | Correct | 89 ms | 768 KB | Output is correct |
63 | Correct | 79 ms | 768 KB | Output is correct |
64 | Correct | 180 ms | 768 KB | Output is correct |
65 | Correct | 182 ms | 768 KB | Output is correct |
66 | Correct | 182 ms | 768 KB | Output is correct |
67 | Correct | 182 ms | 768 KB | Output is correct |
68 | Correct | 180 ms | 768 KB | Output is correct |
69 | Correct | 96 ms | 768 KB | Output is correct |
70 | Correct | 73 ms | 768 KB | Output is correct |
71 | Correct | 74 ms | 768 KB | Output is correct |
72 | Correct | 78 ms | 768 KB | Output is correct |
73 | Correct | 77 ms | 768 KB | Output is correct |
74 | Correct | 18 ms | 768 KB | Output is correct |
75 | Correct | 17 ms | 768 KB | Output is correct |
76 | Correct | 18 ms | 768 KB | Output is correct |
77 | Correct | 18 ms | 768 KB | Output is correct |
78 | Correct | 20 ms | 768 KB | Output is correct |