# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
218157 | 2020-04-01T10:46:28 Z | SamAnd | Boat (APIO16_boat) | C++17 | 1809 ms | 16412 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1003; const int M = 1000000007; int ast(int x, int n) { int ans = 1; while (n) { if (n % 2 == 1) ans = (ans * 1LL * x) % M; x = (x * 1LL * x) % M; n /= 2; } return ans; } int n; int l[N], r[N]; vector<int> v; int C[N][N]; int c[N][N]; int t[N][N]; int dp[N][N]; int p[N][N]; int pp[N][N]; int ans; void rec(int i) { if (i == n + 1) { if (!v.empty()) ++ans; return; } rec(i + 1); for (int j = l[i]; j <= r[i]; ++j) { if (v.empty() || v.back() < j) { v.push_back(j); rec(i + 1); v.pop_back(); } } } int main() { //freopen("input.txt", "r", stdin); scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", &l[i], &r[i]); v.push_back(l[i]); v.push_back(r[i] + 1); } sort(v.begin(), v.end()); vector<int> vv; for (int i = 0; i < v.size(); ++i) { if (!i || v[i] != v[i - 1]) vv.push_back(v[i]); } v = vv; for (int i = 0; i <= n; ++i) { C[i][0] = 1; for (int j = 1; j <= i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % M; } for (int i = 0; i < v.size() - 1; ++i) { for (int k = 0; k <= n; ++k) { c[i][k] = 1; int f = 1; for (int j = 1; j <= k; ++j) { c[i][k] = (c[i][k] * 1LL * (v[i + 1] - v[i] - j + 1)) % M; f = (f * 1LL * j) % M; } c[i][k] = (c[i][k] * 1LL * ast(f, M - 2)) % M; } t[i][1] = c[i][1]; for (int q = 2; q <= n; ++q) { for (int k = 0; k <= q - 2; ++k) { t[i][q] = (t[i][q] + c[i][k + 2] * 1LL * C[q - 2][k]) % M; } } } for (int i = 1; i <= n; ++i) { for (int j = 0; j < v.size() - 1; ++j) { if (!(l[i] <= v[j] && v[j + 1] - 1 <= r[i])) continue; int q = 0; for (int k = i; k >= 1; --k) { if (!(l[k] <= v[j] && v[j + 1] - 1 <= r[k])) continue; ++q; if (k - 1 == 0 || j - 1 == -1) { dp[i][j] = (dp[i][j] + t[j][q]) % M; } else { dp[i][j] = (dp[i][j] + (pp[k - 1][j - 1] + 1) * 1LL * t[j][q]) % M; } } } for (int j = 0; j < v.size() - 1; ++j) { p[i][j] = (p[i - 1][j] + dp[i][j]) % M; } pp[i][0] = p[i][0]; for (int j = 1; j < v.size() - 1; ++j) pp[i][j] = (pp[i][j - 1] + p[i][j]) % M; } printf("%d\n", pp[n][v.size() - 2]); //v.clear(); //rec(1); //printf("%d\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1449 ms | 15736 KB | Output is correct |
2 | Correct | 1455 ms | 15764 KB | Output is correct |
3 | Correct | 1461 ms | 15992 KB | Output is correct |
4 | Correct | 1444 ms | 15736 KB | Output is correct |
5 | Correct | 1452 ms | 15864 KB | Output is correct |
6 | Correct | 1439 ms | 16120 KB | Output is correct |
7 | Correct | 1445 ms | 15992 KB | Output is correct |
8 | Correct | 1470 ms | 16120 KB | Output is correct |
9 | Correct | 1491 ms | 16096 KB | Output is correct |
10 | Correct | 1441 ms | 16132 KB | Output is correct |
11 | Correct | 1444 ms | 15992 KB | Output is correct |
12 | Correct | 1439 ms | 15968 KB | Output is correct |
13 | Correct | 1468 ms | 16120 KB | Output is correct |
14 | Correct | 1487 ms | 16248 KB | Output is correct |
15 | Correct | 1448 ms | 15992 KB | Output is correct |
16 | Correct | 267 ms | 9600 KB | Output is correct |
17 | Correct | 279 ms | 9592 KB | Output is correct |
18 | Correct | 271 ms | 9596 KB | Output is correct |
19 | Correct | 282 ms | 9640 KB | Output is correct |
20 | Correct | 274 ms | 9592 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1449 ms | 15736 KB | Output is correct |
2 | Correct | 1455 ms | 15764 KB | Output is correct |
3 | Correct | 1461 ms | 15992 KB | Output is correct |
4 | Correct | 1444 ms | 15736 KB | Output is correct |
5 | Correct | 1452 ms | 15864 KB | Output is correct |
6 | Correct | 1439 ms | 16120 KB | Output is correct |
7 | Correct | 1445 ms | 15992 KB | Output is correct |
8 | Correct | 1470 ms | 16120 KB | Output is correct |
9 | Correct | 1491 ms | 16096 KB | Output is correct |
10 | Correct | 1441 ms | 16132 KB | Output is correct |
11 | Correct | 1444 ms | 15992 KB | Output is correct |
12 | Correct | 1439 ms | 15968 KB | Output is correct |
13 | Correct | 1468 ms | 16120 KB | Output is correct |
14 | Correct | 1487 ms | 16248 KB | Output is correct |
15 | Correct | 1448 ms | 15992 KB | Output is correct |
16 | Correct | 267 ms | 9600 KB | Output is correct |
17 | Correct | 279 ms | 9592 KB | Output is correct |
18 | Correct | 271 ms | 9596 KB | Output is correct |
19 | Correct | 282 ms | 9640 KB | Output is correct |
20 | Correct | 274 ms | 9592 KB | Output is correct |
21 | Correct | 1466 ms | 15452 KB | Output is correct |
22 | Correct | 1470 ms | 15608 KB | Output is correct |
23 | Correct | 1440 ms | 15516 KB | Output is correct |
24 | Correct | 1453 ms | 15288 KB | Output is correct |
25 | Correct | 1463 ms | 15224 KB | Output is correct |
26 | Correct | 1590 ms | 15224 KB | Output is correct |
27 | Correct | 1612 ms | 15352 KB | Output is correct |
28 | Correct | 1562 ms | 15096 KB | Output is correct |
29 | Correct | 1605 ms | 15352 KB | Output is correct |
30 | Correct | 1480 ms | 15992 KB | Output is correct |
31 | Correct | 1462 ms | 15992 KB | Output is correct |
32 | Correct | 1442 ms | 15996 KB | Output is correct |
33 | Correct | 1454 ms | 16028 KB | Output is correct |
34 | Correct | 1436 ms | 16280 KB | Output is correct |
35 | Correct | 1447 ms | 15992 KB | Output is correct |
36 | Correct | 1447 ms | 15952 KB | Output is correct |
37 | Correct | 1437 ms | 15736 KB | Output is correct |
38 | Correct | 1442 ms | 15912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 3456 KB | Output is correct |
2 | Correct | 21 ms | 3448 KB | Output is correct |
3 | Correct | 21 ms | 3456 KB | Output is correct |
4 | Correct | 22 ms | 3456 KB | Output is correct |
5 | Correct | 22 ms | 3456 KB | Output is correct |
6 | Correct | 23 ms | 3492 KB | Output is correct |
7 | Correct | 25 ms | 3516 KB | Output is correct |
8 | Correct | 23 ms | 3456 KB | Output is correct |
9 | Correct | 23 ms | 3456 KB | Output is correct |
10 | Correct | 23 ms | 3456 KB | Output is correct |
11 | Correct | 22 ms | 3456 KB | Output is correct |
12 | Correct | 21 ms | 3456 KB | Output is correct |
13 | Correct | 21 ms | 3456 KB | Output is correct |
14 | Correct | 22 ms | 3456 KB | Output is correct |
15 | Correct | 23 ms | 3536 KB | Output is correct |
16 | Correct | 15 ms | 2816 KB | Output is correct |
17 | Correct | 14 ms | 2816 KB | Output is correct |
18 | Correct | 15 ms | 2816 KB | Output is correct |
19 | Correct | 15 ms | 2816 KB | Output is correct |
20 | Correct | 14 ms | 2816 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1449 ms | 15736 KB | Output is correct |
2 | Correct | 1455 ms | 15764 KB | Output is correct |
3 | Correct | 1461 ms | 15992 KB | Output is correct |
4 | Correct | 1444 ms | 15736 KB | Output is correct |
5 | Correct | 1452 ms | 15864 KB | Output is correct |
6 | Correct | 1439 ms | 16120 KB | Output is correct |
7 | Correct | 1445 ms | 15992 KB | Output is correct |
8 | Correct | 1470 ms | 16120 KB | Output is correct |
9 | Correct | 1491 ms | 16096 KB | Output is correct |
10 | Correct | 1441 ms | 16132 KB | Output is correct |
11 | Correct | 1444 ms | 15992 KB | Output is correct |
12 | Correct | 1439 ms | 15968 KB | Output is correct |
13 | Correct | 1468 ms | 16120 KB | Output is correct |
14 | Correct | 1487 ms | 16248 KB | Output is correct |
15 | Correct | 1448 ms | 15992 KB | Output is correct |
16 | Correct | 267 ms | 9600 KB | Output is correct |
17 | Correct | 279 ms | 9592 KB | Output is correct |
18 | Correct | 271 ms | 9596 KB | Output is correct |
19 | Correct | 282 ms | 9640 KB | Output is correct |
20 | Correct | 274 ms | 9592 KB | Output is correct |
21 | Correct | 1466 ms | 15452 KB | Output is correct |
22 | Correct | 1470 ms | 15608 KB | Output is correct |
23 | Correct | 1440 ms | 15516 KB | Output is correct |
24 | Correct | 1453 ms | 15288 KB | Output is correct |
25 | Correct | 1463 ms | 15224 KB | Output is correct |
26 | Correct | 1590 ms | 15224 KB | Output is correct |
27 | Correct | 1612 ms | 15352 KB | Output is correct |
28 | Correct | 1562 ms | 15096 KB | Output is correct |
29 | Correct | 1605 ms | 15352 KB | Output is correct |
30 | Correct | 1480 ms | 15992 KB | Output is correct |
31 | Correct | 1462 ms | 15992 KB | Output is correct |
32 | Correct | 1442 ms | 15996 KB | Output is correct |
33 | Correct | 1454 ms | 16028 KB | Output is correct |
34 | Correct | 1436 ms | 16280 KB | Output is correct |
35 | Correct | 1447 ms | 15992 KB | Output is correct |
36 | Correct | 1447 ms | 15952 KB | Output is correct |
37 | Correct | 1437 ms | 15736 KB | Output is correct |
38 | Correct | 1442 ms | 15912 KB | Output is correct |
39 | Correct | 21 ms | 3456 KB | Output is correct |
40 | Correct | 21 ms | 3448 KB | Output is correct |
41 | Correct | 21 ms | 3456 KB | Output is correct |
42 | Correct | 22 ms | 3456 KB | Output is correct |
43 | Correct | 22 ms | 3456 KB | Output is correct |
44 | Correct | 23 ms | 3492 KB | Output is correct |
45 | Correct | 25 ms | 3516 KB | Output is correct |
46 | Correct | 23 ms | 3456 KB | Output is correct |
47 | Correct | 23 ms | 3456 KB | Output is correct |
48 | Correct | 23 ms | 3456 KB | Output is correct |
49 | Correct | 22 ms | 3456 KB | Output is correct |
50 | Correct | 21 ms | 3456 KB | Output is correct |
51 | Correct | 21 ms | 3456 KB | Output is correct |
52 | Correct | 22 ms | 3456 KB | Output is correct |
53 | Correct | 23 ms | 3536 KB | Output is correct |
54 | Correct | 15 ms | 2816 KB | Output is correct |
55 | Correct | 14 ms | 2816 KB | Output is correct |
56 | Correct | 15 ms | 2816 KB | Output is correct |
57 | Correct | 15 ms | 2816 KB | Output is correct |
58 | Correct | 14 ms | 2816 KB | Output is correct |
59 | Correct | 1605 ms | 16412 KB | Output is correct |
60 | Correct | 1601 ms | 16248 KB | Output is correct |
61 | Correct | 1578 ms | 16120 KB | Output is correct |
62 | Correct | 1602 ms | 16120 KB | Output is correct |
63 | Correct | 1594 ms | 16360 KB | Output is correct |
64 | Correct | 1790 ms | 16248 KB | Output is correct |
65 | Correct | 1793 ms | 16120 KB | Output is correct |
66 | Correct | 1779 ms | 16152 KB | Output is correct |
67 | Correct | 1809 ms | 16216 KB | Output is correct |
68 | Correct | 1783 ms | 16224 KB | Output is correct |
69 | Correct | 1576 ms | 16296 KB | Output is correct |
70 | Correct | 1581 ms | 16092 KB | Output is correct |
71 | Correct | 1576 ms | 16248 KB | Output is correct |
72 | Correct | 1586 ms | 16248 KB | Output is correct |
73 | Correct | 1572 ms | 16120 KB | Output is correct |
74 | Correct | 297 ms | 9592 KB | Output is correct |
75 | Correct | 305 ms | 9592 KB | Output is correct |
76 | Correct | 304 ms | 9592 KB | Output is correct |
77 | Correct | 301 ms | 9592 KB | Output is correct |
78 | Correct | 306 ms | 9720 KB | Output is correct |