# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
109551 | 2019-05-07T04:02:47 Z | PeppaPig | Boat (APIO16_boat) | C++14 | 974 ms | 4472 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 1005; const int M = 1e9+7; long inv[N]; long modpow(long a, long b) { long ret = 1; for( ; b; b >>= 1) { if(b & 1) ret = (ret * a) % M; a = (a * a) % M; } return ret; } int n, a[N], b[N]; long dp[N][N]; vector<int> coord; int main() { for(int i = 1; i < N; i++) inv[i] = modpow(i, M-2); scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d %d", a+i, b+i); coord.emplace_back(a[i]); coord.emplace_back(++b[i]); } sort(coord.begin(), coord.end()); coord.resize(unique(coord.begin(), coord.end()) - coord.begin()); for(int i = 1; i <= n; i++) { a[i] = lower_bound(coord.begin(), coord.end(), a[i]) - coord.begin() + 1; b[i] = lower_bound(coord.begin(), coord.end(), b[i]) - coord.begin() + 1; } for(int i = 0; i < N; i++) dp[0][i] = 1; for(int i = 1; i <= n; i++) { for(int j = a[i]; j < b[i]; j++) { long p = coord[j] - coord[j-1], cnt = 1; for(int k = i-1; ~k; k--) { dp[i][j] = (dp[i][j] + (p * dp[k][j-1]) % M) % M; if(a[k] <= j && j < b[k]) { ++cnt; p = (p * (coord[j] - coord[j-1] + cnt - 1)) % M; p = (p * inv[cnt]) % M; } } } for(int j = 1; j < N; j++) dp[i][j] = (dp[i][j] + dp[i][j-1]) % M; } long ans = 0; for(int i = 1; i <= n; i++) ans = (ans + dp[i][N-1]) % M; printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 4352 KB | Output is correct |
2 | Correct | 14 ms | 4224 KB | Output is correct |
3 | Correct | 14 ms | 4352 KB | Output is correct |
4 | Correct | 14 ms | 4352 KB | Output is correct |
5 | Correct | 14 ms | 4352 KB | Output is correct |
6 | Correct | 13 ms | 4352 KB | Output is correct |
7 | Correct | 12 ms | 4268 KB | Output is correct |
8 | Correct | 14 ms | 4352 KB | Output is correct |
9 | Correct | 16 ms | 4324 KB | Output is correct |
10 | Correct | 16 ms | 4344 KB | Output is correct |
11 | Correct | 13 ms | 4352 KB | Output is correct |
12 | Correct | 14 ms | 4224 KB | Output is correct |
13 | Correct | 12 ms | 4224 KB | Output is correct |
14 | Correct | 13 ms | 4352 KB | Output is correct |
15 | Correct | 14 ms | 4216 KB | Output is correct |
16 | Correct | 13 ms | 4224 KB | Output is correct |
17 | Correct | 14 ms | 4224 KB | Output is correct |
18 | Correct | 12 ms | 4352 KB | Output is correct |
19 | Correct | 14 ms | 4224 KB | Output is correct |
20 | Correct | 14 ms | 4352 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 4352 KB | Output is correct |
2 | Correct | 14 ms | 4224 KB | Output is correct |
3 | Correct | 14 ms | 4352 KB | Output is correct |
4 | Correct | 14 ms | 4352 KB | Output is correct |
5 | Correct | 14 ms | 4352 KB | Output is correct |
6 | Correct | 13 ms | 4352 KB | Output is correct |
7 | Correct | 12 ms | 4268 KB | Output is correct |
8 | Correct | 14 ms | 4352 KB | Output is correct |
9 | Correct | 16 ms | 4324 KB | Output is correct |
10 | Correct | 16 ms | 4344 KB | Output is correct |
11 | Correct | 13 ms | 4352 KB | Output is correct |
12 | Correct | 14 ms | 4224 KB | Output is correct |
13 | Correct | 12 ms | 4224 KB | Output is correct |
14 | Correct | 13 ms | 4352 KB | Output is correct |
15 | Correct | 14 ms | 4216 KB | Output is correct |
16 | Correct | 13 ms | 4224 KB | Output is correct |
17 | Correct | 14 ms | 4224 KB | Output is correct |
18 | Correct | 12 ms | 4352 KB | Output is correct |
19 | Correct | 14 ms | 4224 KB | Output is correct |
20 | Correct | 14 ms | 4352 KB | Output is correct |
21 | Correct | 734 ms | 4224 KB | Output is correct |
22 | Correct | 669 ms | 4336 KB | Output is correct |
23 | Correct | 562 ms | 4344 KB | Output is correct |
24 | Correct | 559 ms | 4216 KB | Output is correct |
25 | Correct | 528 ms | 4380 KB | Output is correct |
26 | Correct | 653 ms | 4368 KB | Output is correct |
27 | Correct | 700 ms | 4472 KB | Output is correct |
28 | Correct | 691 ms | 4404 KB | Output is correct |
29 | Correct | 974 ms | 4368 KB | Output is correct |
30 | Correct | 18 ms | 4224 KB | Output is correct |
31 | Correct | 15 ms | 4224 KB | Output is correct |
32 | Correct | 17 ms | 4344 KB | Output is correct |
33 | Correct | 17 ms | 4352 KB | Output is correct |
34 | Correct | 16 ms | 4224 KB | Output is correct |
35 | Correct | 17 ms | 4224 KB | Output is correct |
36 | Correct | 18 ms | 4224 KB | Output is correct |
37 | Correct | 16 ms | 4224 KB | Output is correct |
38 | Correct | 19 ms | 4316 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 1152 KB | Output is correct |
2 | Correct | 6 ms | 1152 KB | Output is correct |
3 | Correct | 11 ms | 1152 KB | Output is correct |
4 | Correct | 7 ms | 1152 KB | Output is correct |
5 | Correct | 7 ms | 1152 KB | Output is correct |
6 | Correct | 8 ms | 1152 KB | Output is correct |
7 | Correct | 9 ms | 1152 KB | Output is correct |
8 | Correct | 8 ms | 1152 KB | Output is correct |
9 | Correct | 9 ms | 1152 KB | Output is correct |
10 | Correct | 9 ms | 1152 KB | Output is correct |
11 | Correct | 6 ms | 1152 KB | Output is correct |
12 | Correct | 8 ms | 1152 KB | Output is correct |
13 | Correct | 7 ms | 1152 KB | Output is correct |
14 | Correct | 6 ms | 1152 KB | Output is correct |
15 | Correct | 8 ms | 1152 KB | Output is correct |
16 | Correct | 6 ms | 1152 KB | Output is correct |
17 | Correct | 5 ms | 1152 KB | Output is correct |
18 | Correct | 5 ms | 1152 KB | Output is correct |
19 | Correct | 5 ms | 1152 KB | Output is correct |
20 | Correct | 7 ms | 1152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 4352 KB | Output is correct |
2 | Correct | 14 ms | 4224 KB | Output is correct |
3 | Correct | 14 ms | 4352 KB | Output is correct |
4 | Correct | 14 ms | 4352 KB | Output is correct |
5 | Correct | 14 ms | 4352 KB | Output is correct |
6 | Correct | 13 ms | 4352 KB | Output is correct |
7 | Correct | 12 ms | 4268 KB | Output is correct |
8 | Correct | 14 ms | 4352 KB | Output is correct |
9 | Correct | 16 ms | 4324 KB | Output is correct |
10 | Correct | 16 ms | 4344 KB | Output is correct |
11 | Correct | 13 ms | 4352 KB | Output is correct |
12 | Correct | 14 ms | 4224 KB | Output is correct |
13 | Correct | 12 ms | 4224 KB | Output is correct |
14 | Correct | 13 ms | 4352 KB | Output is correct |
15 | Correct | 14 ms | 4216 KB | Output is correct |
16 | Correct | 13 ms | 4224 KB | Output is correct |
17 | Correct | 14 ms | 4224 KB | Output is correct |
18 | Correct | 12 ms | 4352 KB | Output is correct |
19 | Correct | 14 ms | 4224 KB | Output is correct |
20 | Correct | 14 ms | 4352 KB | Output is correct |
21 | Correct | 734 ms | 4224 KB | Output is correct |
22 | Correct | 669 ms | 4336 KB | Output is correct |
23 | Correct | 562 ms | 4344 KB | Output is correct |
24 | Correct | 559 ms | 4216 KB | Output is correct |
25 | Correct | 528 ms | 4380 KB | Output is correct |
26 | Correct | 653 ms | 4368 KB | Output is correct |
27 | Correct | 700 ms | 4472 KB | Output is correct |
28 | Correct | 691 ms | 4404 KB | Output is correct |
29 | Correct | 974 ms | 4368 KB | Output is correct |
30 | Correct | 18 ms | 4224 KB | Output is correct |
31 | Correct | 15 ms | 4224 KB | Output is correct |
32 | Correct | 17 ms | 4344 KB | Output is correct |
33 | Correct | 17 ms | 4352 KB | Output is correct |
34 | Correct | 16 ms | 4224 KB | Output is correct |
35 | Correct | 17 ms | 4224 KB | Output is correct |
36 | Correct | 18 ms | 4224 KB | Output is correct |
37 | Correct | 16 ms | 4224 KB | Output is correct |
38 | Correct | 19 ms | 4316 KB | Output is correct |
39 | Correct | 27 ms | 1152 KB | Output is correct |
40 | Correct | 6 ms | 1152 KB | Output is correct |
41 | Correct | 11 ms | 1152 KB | Output is correct |
42 | Correct | 7 ms | 1152 KB | Output is correct |
43 | Correct | 7 ms | 1152 KB | Output is correct |
44 | Correct | 8 ms | 1152 KB | Output is correct |
45 | Correct | 9 ms | 1152 KB | Output is correct |
46 | Correct | 8 ms | 1152 KB | Output is correct |
47 | Correct | 9 ms | 1152 KB | Output is correct |
48 | Correct | 9 ms | 1152 KB | Output is correct |
49 | Correct | 6 ms | 1152 KB | Output is correct |
50 | Correct | 8 ms | 1152 KB | Output is correct |
51 | Correct | 7 ms | 1152 KB | Output is correct |
52 | Correct | 6 ms | 1152 KB | Output is correct |
53 | Correct | 8 ms | 1152 KB | Output is correct |
54 | Correct | 6 ms | 1152 KB | Output is correct |
55 | Correct | 5 ms | 1152 KB | Output is correct |
56 | Correct | 5 ms | 1152 KB | Output is correct |
57 | Correct | 5 ms | 1152 KB | Output is correct |
58 | Correct | 7 ms | 1152 KB | Output is correct |
59 | Correct | 824 ms | 4240 KB | Output is correct |
60 | Correct | 830 ms | 4292 KB | Output is correct |
61 | Correct | 706 ms | 4264 KB | Output is correct |
62 | Correct | 737 ms | 4344 KB | Output is correct |
63 | Correct | 689 ms | 4472 KB | Output is correct |
64 | Correct | 901 ms | 4392 KB | Output is correct |
65 | Correct | 824 ms | 4360 KB | Output is correct |
66 | Correct | 834 ms | 4248 KB | Output is correct |
67 | Correct | 849 ms | 4408 KB | Output is correct |
68 | Correct | 827 ms | 4296 KB | Output is correct |
69 | Correct | 398 ms | 4252 KB | Output is correct |
70 | Correct | 475 ms | 4332 KB | Output is correct |
71 | Correct | 394 ms | 4472 KB | Output is correct |
72 | Correct | 391 ms | 4316 KB | Output is correct |
73 | Correct | 428 ms | 4396 KB | Output is correct |
74 | Correct | 90 ms | 4344 KB | Output is correct |
75 | Correct | 118 ms | 4300 KB | Output is correct |
76 | Correct | 106 ms | 4216 KB | Output is correct |
77 | Correct | 101 ms | 4272 KB | Output is correct |
78 | Correct | 97 ms | 4344 KB | Output is correct |