답안 #47662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47662 2018-05-06T07:56:50 Z square1001 Boat (APIO16_boat) C++14
100 / 100
442 ms 4724 KB
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
int n, c, a[509], b[509], x[1009], inv[509], comb[1009][509], dp[509][1009];
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
		x[i] = a[i];
		x[i + n] = ++b[i];
	}
	sort(x, x + 2 * n);
	c = unique(x, x + 2 * n) - x;
	for (int i = 0; i < n; ++i) {
		a[i] = lower_bound(x, x + c, a[i]) - x;
		b[i] = lower_bound(x, x + c, b[i]) - x;
	}
	inv[1] = 1;
	for (int i = 2; i <= n; ++i) {
		inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	}
	for (int i = 0; i < c - 1; ++i) {
		int way = 1;
		for (int j = 1; j <= n; ++j) {
			way = 1LL * way * (x[i + 1] - x[i] + j - 1) % mod * inv[j] % mod;
			comb[i][j] = way;
			if (comb[i][j] >= mod) comb[i][j] -= mod;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = a[i]; j < b[i]; ++j) {
			int num = 0;
			for (int k = i - 1; k >= 0; --k) {
				if (a[k + 1] <= j && j < b[k + 1]) ++num;
				dp[i][j + 1] = (dp[i][j + 1] + 1LL * comb[j][num] * dp[k][j]) % mod;
			}
			if (a[0] <= j && j < b[0]) ++num;
			dp[i][j + 1] += comb[j][num];
			if (dp[i][j + 1] >= mod) dp[i][j + 1] -= mod;
		}
		for (int j = 0; j < c - 1; ++j) {
			dp[i][j + 1] += dp[i][j];
			if (dp[i][j + 1] >= mod) dp[i][j + 1] -= mod;
		}
		ans += dp[i][c - 1];
		if (ans >= mod) ans -= mod;
	}
	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4348 KB Output is correct
2 Correct 16 ms 4584 KB Output is correct
3 Correct 15 ms 4640 KB Output is correct
4 Correct 15 ms 4640 KB Output is correct
5 Correct 17 ms 4640 KB Output is correct
6 Correct 16 ms 4640 KB Output is correct
7 Correct 15 ms 4640 KB Output is correct
8 Correct 15 ms 4640 KB Output is correct
9 Correct 15 ms 4640 KB Output is correct
10 Correct 15 ms 4640 KB Output is correct
11 Correct 15 ms 4640 KB Output is correct
12 Correct 15 ms 4640 KB Output is correct
13 Correct 15 ms 4640 KB Output is correct
14 Correct 15 ms 4640 KB Output is correct
15 Correct 15 ms 4640 KB Output is correct
16 Correct 7 ms 4640 KB Output is correct
17 Correct 7 ms 4640 KB Output is correct
18 Correct 7 ms 4640 KB Output is correct
19 Correct 8 ms 4640 KB Output is correct
20 Correct 7 ms 4640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4348 KB Output is correct
2 Correct 16 ms 4584 KB Output is correct
3 Correct 15 ms 4640 KB Output is correct
4 Correct 15 ms 4640 KB Output is correct
5 Correct 17 ms 4640 KB Output is correct
6 Correct 16 ms 4640 KB Output is correct
7 Correct 15 ms 4640 KB Output is correct
8 Correct 15 ms 4640 KB Output is correct
9 Correct 15 ms 4640 KB Output is correct
10 Correct 15 ms 4640 KB Output is correct
11 Correct 15 ms 4640 KB Output is correct
12 Correct 15 ms 4640 KB Output is correct
13 Correct 15 ms 4640 KB Output is correct
14 Correct 15 ms 4640 KB Output is correct
15 Correct 15 ms 4640 KB Output is correct
16 Correct 7 ms 4640 KB Output is correct
17 Correct 7 ms 4640 KB Output is correct
18 Correct 7 ms 4640 KB Output is correct
19 Correct 8 ms 4640 KB Output is correct
20 Correct 7 ms 4640 KB Output is correct
21 Correct 262 ms 4640 KB Output is correct
22 Correct 251 ms 4640 KB Output is correct
23 Correct 249 ms 4640 KB Output is correct
24 Correct 253 ms 4640 KB Output is correct
25 Correct 263 ms 4640 KB Output is correct
26 Correct 362 ms 4640 KB Output is correct
27 Correct 378 ms 4640 KB Output is correct
28 Correct 360 ms 4640 KB Output is correct
29 Correct 356 ms 4640 KB Output is correct
30 Correct 18 ms 4640 KB Output is correct
31 Correct 17 ms 4640 KB Output is correct
32 Correct 18 ms 4640 KB Output is correct
33 Correct 17 ms 4640 KB Output is correct
34 Correct 16 ms 4640 KB Output is correct
35 Correct 17 ms 4640 KB Output is correct
36 Correct 17 ms 4640 KB Output is correct
37 Correct 17 ms 4640 KB Output is correct
38 Correct 17 ms 4640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4640 KB Output is correct
2 Correct 4 ms 4640 KB Output is correct
3 Correct 4 ms 4640 KB Output is correct
4 Correct 5 ms 4640 KB Output is correct
5 Correct 5 ms 4640 KB Output is correct
6 Correct 6 ms 4640 KB Output is correct
7 Correct 7 ms 4640 KB Output is correct
8 Correct 6 ms 4640 KB Output is correct
9 Correct 6 ms 4640 KB Output is correct
10 Correct 6 ms 4640 KB Output is correct
11 Correct 5 ms 4640 KB Output is correct
12 Correct 4 ms 4640 KB Output is correct
13 Correct 4 ms 4640 KB Output is correct
14 Correct 5 ms 4640 KB Output is correct
15 Correct 4 ms 4640 KB Output is correct
16 Correct 4 ms 4640 KB Output is correct
17 Correct 4 ms 4640 KB Output is correct
18 Correct 4 ms 4640 KB Output is correct
19 Correct 4 ms 4640 KB Output is correct
20 Correct 4 ms 4640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4348 KB Output is correct
2 Correct 16 ms 4584 KB Output is correct
3 Correct 15 ms 4640 KB Output is correct
4 Correct 15 ms 4640 KB Output is correct
5 Correct 17 ms 4640 KB Output is correct
6 Correct 16 ms 4640 KB Output is correct
7 Correct 15 ms 4640 KB Output is correct
8 Correct 15 ms 4640 KB Output is correct
9 Correct 15 ms 4640 KB Output is correct
10 Correct 15 ms 4640 KB Output is correct
11 Correct 15 ms 4640 KB Output is correct
12 Correct 15 ms 4640 KB Output is correct
13 Correct 15 ms 4640 KB Output is correct
14 Correct 15 ms 4640 KB Output is correct
15 Correct 15 ms 4640 KB Output is correct
16 Correct 7 ms 4640 KB Output is correct
17 Correct 7 ms 4640 KB Output is correct
18 Correct 7 ms 4640 KB Output is correct
19 Correct 8 ms 4640 KB Output is correct
20 Correct 7 ms 4640 KB Output is correct
21 Correct 262 ms 4640 KB Output is correct
22 Correct 251 ms 4640 KB Output is correct
23 Correct 249 ms 4640 KB Output is correct
24 Correct 253 ms 4640 KB Output is correct
25 Correct 263 ms 4640 KB Output is correct
26 Correct 362 ms 4640 KB Output is correct
27 Correct 378 ms 4640 KB Output is correct
28 Correct 360 ms 4640 KB Output is correct
29 Correct 356 ms 4640 KB Output is correct
30 Correct 18 ms 4640 KB Output is correct
31 Correct 17 ms 4640 KB Output is correct
32 Correct 18 ms 4640 KB Output is correct
33 Correct 17 ms 4640 KB Output is correct
34 Correct 16 ms 4640 KB Output is correct
35 Correct 17 ms 4640 KB Output is correct
36 Correct 17 ms 4640 KB Output is correct
37 Correct 17 ms 4640 KB Output is correct
38 Correct 17 ms 4640 KB Output is correct
39 Correct 5 ms 4640 KB Output is correct
40 Correct 4 ms 4640 KB Output is correct
41 Correct 4 ms 4640 KB Output is correct
42 Correct 5 ms 4640 KB Output is correct
43 Correct 5 ms 4640 KB Output is correct
44 Correct 6 ms 4640 KB Output is correct
45 Correct 7 ms 4640 KB Output is correct
46 Correct 6 ms 4640 KB Output is correct
47 Correct 6 ms 4640 KB Output is correct
48 Correct 6 ms 4640 KB Output is correct
49 Correct 5 ms 4640 KB Output is correct
50 Correct 4 ms 4640 KB Output is correct
51 Correct 4 ms 4640 KB Output is correct
52 Correct 5 ms 4640 KB Output is correct
53 Correct 4 ms 4640 KB Output is correct
54 Correct 4 ms 4640 KB Output is correct
55 Correct 4 ms 4640 KB Output is correct
56 Correct 4 ms 4640 KB Output is correct
57 Correct 4 ms 4640 KB Output is correct
58 Correct 4 ms 4640 KB Output is correct
59 Correct 294 ms 4640 KB Output is correct
60 Correct 283 ms 4640 KB Output is correct
61 Correct 257 ms 4640 KB Output is correct
62 Correct 304 ms 4640 KB Output is correct
63 Correct 285 ms 4640 KB Output is correct
64 Correct 411 ms 4720 KB Output is correct
65 Correct 417 ms 4720 KB Output is correct
66 Correct 442 ms 4720 KB Output is correct
67 Correct 430 ms 4720 KB Output is correct
68 Correct 423 ms 4720 KB Output is correct
69 Correct 231 ms 4720 KB Output is correct
70 Correct 231 ms 4720 KB Output is correct
71 Correct 219 ms 4720 KB Output is correct
72 Correct 231 ms 4720 KB Output is correct
73 Correct 229 ms 4724 KB Output is correct
74 Correct 60 ms 4724 KB Output is correct
75 Correct 65 ms 4724 KB Output is correct
76 Correct 61 ms 4724 KB Output is correct
77 Correct 60 ms 4724 KB Output is correct
78 Correct 62 ms 4724 KB Output is correct