Submission #556963

# Submission time Handle Problem Language Result Execution time Memory
556963 2022-05-04T13:00:28 Z hollwo_pelw Boat (APIO16_boat) C++17
100 / 100
300 ms 2376 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 505, mod = 1e9 + 7;

int n, m, a[N], b[N], cnt[N * 2], dp[N * 2][N], inv[N];
vector<int> v, f;

signed main(){
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i], b[i] ++;

	inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = mod - 1ll * (mod / i) * inv[mod % i] % mod;

	for (int i = 1; i <= n; i++)
		v.push_back(a[i]), v.push_back(b[i]);

	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());

	f.resize(m = v.size() - 1);
	for (int i = 1; i < (int) v.size(); i++)
		f[i - 1] = v[i] - v[i - 1];
	
	for (int i = 1; i <= n; i++) {
		int l = lower_bound(v.begin(), v.end(), a[i]) - v.begin(), r = lower_bound(v.begin(), v.end(), b[i]) - v.begin(), cur = 1;

		for (int j = 0; j < l; j++) {
			for (int k = cnt[j]; k; k--)
				if ((cur += dp[j][k]) >= mod)
					cur -= mod;
		}

		for (int j = l; j < r; j++) {
			int nxt = cur;
			for (int k = cnt[j]; k; k--) {
				if ((nxt += dp[j][k]) >= mod)
					nxt -= mod;
				dp[j][k + 1] += 1ll * dp[j][k] * (f[j] - k) % mod * inv[k + 1] % mod;
				if (dp[j][k + 1] >= mod) dp[j][k + 1] -= mod;
			}
			++ cnt[j];

			dp[j][1] += 1ll * cur * f[j] % mod;
			if (dp[j][1] >= mod) dp[j][1] -= mod;

			swap(nxt, cur);
		}
	}

	int res = 0;
	for (int j = 0; j < m; j++)
		for (int k = 1; k <= cnt[j]; k++)
			if ((res += dp[j][k]) >= mod)
				res -= mod;
	cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 3 ms 2264 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 2 ms 2256 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 2 ms 2260 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2256 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 2 ms 2260 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 3 ms 2264 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 2 ms 2256 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 2 ms 2260 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2256 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 2 ms 2260 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 117 ms 2148 KB Output is correct
22 Correct 112 ms 2128 KB Output is correct
23 Correct 98 ms 2128 KB Output is correct
24 Correct 146 ms 2004 KB Output is correct
25 Correct 109 ms 2132 KB Output is correct
26 Correct 231 ms 2044 KB Output is correct
27 Correct 268 ms 2124 KB Output is correct
28 Correct 242 ms 2084 KB Output is correct
29 Correct 233 ms 2020 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 3 ms 2260 KB Output is correct
32 Correct 2 ms 2260 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 3 ms 2272 KB Output is correct
35 Correct 3 ms 2260 KB Output is correct
36 Correct 2 ms 2260 KB Output is correct
37 Correct 2 ms 2260 KB Output is correct
38 Correct 4 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 4 ms 716 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 2 ms 732 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 3 ms 2264 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 2 ms 2256 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 2 ms 2260 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 2260 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2256 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 2 ms 2260 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 117 ms 2148 KB Output is correct
22 Correct 112 ms 2128 KB Output is correct
23 Correct 98 ms 2128 KB Output is correct
24 Correct 146 ms 2004 KB Output is correct
25 Correct 109 ms 2132 KB Output is correct
26 Correct 231 ms 2044 KB Output is correct
27 Correct 268 ms 2124 KB Output is correct
28 Correct 242 ms 2084 KB Output is correct
29 Correct 233 ms 2020 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 3 ms 2260 KB Output is correct
32 Correct 2 ms 2260 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 3 ms 2272 KB Output is correct
35 Correct 3 ms 2260 KB Output is correct
36 Correct 2 ms 2260 KB Output is correct
37 Correct 2 ms 2260 KB Output is correct
38 Correct 4 ms 2260 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 4 ms 716 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 3 ms 724 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 4 ms 724 KB Output is correct
49 Correct 2 ms 732 KB Output is correct
50 Correct 2 ms 716 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 2 ms 724 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 128 ms 2316 KB Output is correct
60 Correct 112 ms 2324 KB Output is correct
61 Correct 104 ms 2312 KB Output is correct
62 Correct 148 ms 2328 KB Output is correct
63 Correct 122 ms 2260 KB Output is correct
64 Correct 270 ms 2276 KB Output is correct
65 Correct 276 ms 2288 KB Output is correct
66 Correct 300 ms 2376 KB Output is correct
67 Correct 268 ms 2260 KB Output is correct
68 Correct 265 ms 2272 KB Output is correct
69 Correct 131 ms 2300 KB Output is correct
70 Correct 127 ms 2260 KB Output is correct
71 Correct 120 ms 2260 KB Output is correct
72 Correct 142 ms 2260 KB Output is correct
73 Correct 129 ms 2316 KB Output is correct
74 Correct 25 ms 700 KB Output is correct
75 Correct 22 ms 724 KB Output is correct
76 Correct 23 ms 592 KB Output is correct
77 Correct 24 ms 600 KB Output is correct
78 Correct 25 ms 596 KB Output is correct