# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
108389 | 2019-04-29T04:04:57 Z | kuroni | Boat (APIO16_boat) | C++17 | 224 ms | 504 KB |
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int N = 510, MOD = 1E9 + 7; int n, l, r; bool vis[N]; long long ans = 0, f[N], g[N], c[N], inv[N]; vector<pair<int, int>> sw; vector<int> ve; void init() { c[0] = 1; vis[0] = true; for (int i = 0; i <= n; i++) f[i] = 1; inv[1] = 1; for (int i = 2; i <= n; i++) inv[i] = MOD - MOD / i * inv[MOD % i] % MOD; } long long sum(int l, int r) { return f[r] - (l == 0 ? 0 : f[l - 1]); } long long solve(int u, int len) { long long ret = 0; vis[u] = !vis[u]; ve.clear(); for (int i = 0; i <= n; i++) if (vis[i]) ve.push_back(i); for (int i = 1; i < (int)ve.size(); i++) c[i] = c[i - 1] * (len + i - 1) % MOD * inv[i] % MOD; for (int i = 1; i < (int)ve.size(); i++) for (int j = 0; j < i; j++) (g[ve[i]] += c[i - j] * sum(ve[j], ve[j + 1] - 1)) %= MOD; for (int i = 1; i <= n; i++) { (ret += g[i]) %= MOD; (f[i] += ret) %= MOD; g[i] = 0; } return ret; } int main() { scanf("%d", &n); init(); for (int i = 1; i <= n; i++) { scanf("%d%d", &l, &r); sw.push_back({l, i}); sw.push_back({r + 1, i}); } sort(sw.begin(), sw.end()); for (int i = 0; i < (int)sw.size() - 1; i++) (ans += solve(sw[i].second, sw[i + 1].first - sw[i].first)) %= MOD; printf("%lld\n", (ans + MOD) % MOD); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 384 KB | Output is correct |
2 | Correct | 7 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 6 ms | 384 KB | Output is correct |
5 | Correct | 6 ms | 384 KB | Output is correct |
6 | Correct | 6 ms | 384 KB | Output is correct |
7 | Correct | 6 ms | 384 KB | Output is correct |
8 | Correct | 7 ms | 384 KB | Output is correct |
9 | Correct | 7 ms | 384 KB | Output is correct |
10 | Correct | 7 ms | 384 KB | Output is correct |
11 | Correct | 7 ms | 384 KB | Output is correct |
12 | Correct | 7 ms | 384 KB | Output is correct |
13 | Correct | 6 ms | 256 KB | Output is correct |
14 | Correct | 6 ms | 384 KB | Output is correct |
15 | Correct | 7 ms | 384 KB | Output is correct |
16 | Correct | 7 ms | 384 KB | Output is correct |
17 | Correct | 6 ms | 384 KB | Output is correct |
18 | Correct | 6 ms | 384 KB | Output is correct |
19 | Correct | 7 ms | 384 KB | Output is correct |
20 | Correct | 6 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 384 KB | Output is correct |
2 | Correct | 7 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 6 ms | 384 KB | Output is correct |
5 | Correct | 6 ms | 384 KB | Output is correct |
6 | Correct | 6 ms | 384 KB | Output is correct |
7 | Correct | 6 ms | 384 KB | Output is correct |
8 | Correct | 7 ms | 384 KB | Output is correct |
9 | Correct | 7 ms | 384 KB | Output is correct |
10 | Correct | 7 ms | 384 KB | Output is correct |
11 | Correct | 7 ms | 384 KB | Output is correct |
12 | Correct | 7 ms | 384 KB | Output is correct |
13 | Correct | 6 ms | 256 KB | Output is correct |
14 | Correct | 6 ms | 384 KB | Output is correct |
15 | Correct | 7 ms | 384 KB | Output is correct |
16 | Correct | 7 ms | 384 KB | Output is correct |
17 | Correct | 6 ms | 384 KB | Output is correct |
18 | Correct | 6 ms | 384 KB | Output is correct |
19 | Correct | 7 ms | 384 KB | Output is correct |
20 | Correct | 6 ms | 384 KB | Output is correct |
21 | Correct | 89 ms | 324 KB | Output is correct |
22 | Correct | 87 ms | 384 KB | Output is correct |
23 | Correct | 78 ms | 504 KB | Output is correct |
24 | Correct | 86 ms | 424 KB | Output is correct |
25 | Correct | 101 ms | 504 KB | Output is correct |
26 | Correct | 206 ms | 384 KB | Output is correct |
27 | Correct | 202 ms | 384 KB | Output is correct |
28 | Correct | 211 ms | 504 KB | Output is correct |
29 | Correct | 213 ms | 384 KB | Output is correct |
30 | Correct | 7 ms | 384 KB | Output is correct |
31 | Correct | 7 ms | 384 KB | Output is correct |
32 | Correct | 7 ms | 384 KB | Output is correct |
33 | Correct | 7 ms | 384 KB | Output is correct |
34 | Correct | 8 ms | 384 KB | Output is correct |
35 | Correct | 7 ms | 384 KB | Output is correct |
36 | Correct | 7 ms | 384 KB | Output is correct |
37 | Correct | 7 ms | 384 KB | Output is correct |
38 | Correct | 6 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 6 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 3 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 4 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 4 ms | 384 KB | Output is correct |
19 | Correct | 4 ms | 384 KB | Output is correct |
20 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 384 KB | Output is correct |
2 | Correct | 7 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 6 ms | 384 KB | Output is correct |
5 | Correct | 6 ms | 384 KB | Output is correct |
6 | Correct | 6 ms | 384 KB | Output is correct |
7 | Correct | 6 ms | 384 KB | Output is correct |
8 | Correct | 7 ms | 384 KB | Output is correct |
9 | Correct | 7 ms | 384 KB | Output is correct |
10 | Correct | 7 ms | 384 KB | Output is correct |
11 | Correct | 7 ms | 384 KB | Output is correct |
12 | Correct | 7 ms | 384 KB | Output is correct |
13 | Correct | 6 ms | 256 KB | Output is correct |
14 | Correct | 6 ms | 384 KB | Output is correct |
15 | Correct | 7 ms | 384 KB | Output is correct |
16 | Correct | 7 ms | 384 KB | Output is correct |
17 | Correct | 6 ms | 384 KB | Output is correct |
18 | Correct | 6 ms | 384 KB | Output is correct |
19 | Correct | 7 ms | 384 KB | Output is correct |
20 | Correct | 6 ms | 384 KB | Output is correct |
21 | Correct | 89 ms | 324 KB | Output is correct |
22 | Correct | 87 ms | 384 KB | Output is correct |
23 | Correct | 78 ms | 504 KB | Output is correct |
24 | Correct | 86 ms | 424 KB | Output is correct |
25 | Correct | 101 ms | 504 KB | Output is correct |
26 | Correct | 206 ms | 384 KB | Output is correct |
27 | Correct | 202 ms | 384 KB | Output is correct |
28 | Correct | 211 ms | 504 KB | Output is correct |
29 | Correct | 213 ms | 384 KB | Output is correct |
30 | Correct | 7 ms | 384 KB | Output is correct |
31 | Correct | 7 ms | 384 KB | Output is correct |
32 | Correct | 7 ms | 384 KB | Output is correct |
33 | Correct | 7 ms | 384 KB | Output is correct |
34 | Correct | 8 ms | 384 KB | Output is correct |
35 | Correct | 7 ms | 384 KB | Output is correct |
36 | Correct | 7 ms | 384 KB | Output is correct |
37 | Correct | 7 ms | 384 KB | Output is correct |
38 | Correct | 6 ms | 384 KB | Output is correct |
39 | Correct | 4 ms | 384 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 4 ms | 384 KB | Output is correct |
42 | Correct | 6 ms | 384 KB | Output is correct |
43 | Correct | 3 ms | 384 KB | Output is correct |
44 | Correct | 4 ms | 384 KB | Output is correct |
45 | Correct | 4 ms | 384 KB | Output is correct |
46 | Correct | 5 ms | 384 KB | Output is correct |
47 | Correct | 5 ms | 384 KB | Output is correct |
48 | Correct | 4 ms | 384 KB | Output is correct |
49 | Correct | 3 ms | 384 KB | Output is correct |
50 | Correct | 3 ms | 384 KB | Output is correct |
51 | Correct | 3 ms | 384 KB | Output is correct |
52 | Correct | 4 ms | 384 KB | Output is correct |
53 | Correct | 4 ms | 384 KB | Output is correct |
54 | Correct | 3 ms | 384 KB | Output is correct |
55 | Correct | 3 ms | 384 KB | Output is correct |
56 | Correct | 4 ms | 384 KB | Output is correct |
57 | Correct | 4 ms | 384 KB | Output is correct |
58 | Correct | 3 ms | 384 KB | Output is correct |
59 | Correct | 87 ms | 388 KB | Output is correct |
60 | Correct | 78 ms | 384 KB | Output is correct |
61 | Correct | 75 ms | 504 KB | Output is correct |
62 | Correct | 103 ms | 384 KB | Output is correct |
63 | Correct | 86 ms | 504 KB | Output is correct |
64 | Correct | 202 ms | 388 KB | Output is correct |
65 | Correct | 198 ms | 504 KB | Output is correct |
66 | Correct | 208 ms | 384 KB | Output is correct |
67 | Correct | 224 ms | 504 KB | Output is correct |
68 | Correct | 196 ms | 384 KB | Output is correct |
69 | Correct | 77 ms | 384 KB | Output is correct |
70 | Correct | 80 ms | 384 KB | Output is correct |
71 | Correct | 86 ms | 384 KB | Output is correct |
72 | Correct | 86 ms | 428 KB | Output is correct |
73 | Correct | 95 ms | 384 KB | Output is correct |
74 | Correct | 101 ms | 384 KB | Output is correct |
75 | Correct | 84 ms | 384 KB | Output is correct |
76 | Correct | 89 ms | 384 KB | Output is correct |
77 | Correct | 84 ms | 384 KB | Output is correct |
78 | Correct | 106 ms | 504 KB | Output is correct |