Submission #556938

# Submission time Handle Problem Language Result Execution time Memory
556938 2022-05-04T12:04:07 Z hollwo_pelw Boat (APIO16_boat) C++17
100 / 100
271 ms 2384 KB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;

void Hollwo_Pelw();

signed main(){
#ifndef hollwo_pelw_local
	if (fopen("hollwo_pelw.inp", "r"))
		assert(freopen("hollwo_pelw.inp", "r", stdin)), assert(freopen("hollwo_pelw.out", "w", stdout));
#else
	using namespace chrono;
	auto start = steady_clock::now();
#endif
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
	int testcases = 1;
	// cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = steady_clock::now();
	cout << "\nExcution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}

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;

void Hollwo_Pelw(){
	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 = 0; i < m; i++)
	// 	cout << f[i] << " \n"[i == m - 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();

		int 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);
		}

		// cout << "solve " << i << '\n';
		// for (int j = 0; j < m; j++) if (cnt[j]) {
		// 	cout << "j = " << j << " : ";
		// 	for (int k = 1; k <= cnt[j]; k++)
		// 		cout << dp[j][k] << " \n"[k == cnt[j]];
		// }
	}

	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 2 ms 2264 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
7 Correct 2 ms 2260 KB Output is correct
8 Correct 2 ms 2264 KB Output is correct
9 Correct 2 ms 2260 KB Output is correct
10 Correct 3 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 2260 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 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 2 ms 2264 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
7 Correct 2 ms 2260 KB Output is correct
8 Correct 2 ms 2264 KB Output is correct
9 Correct 2 ms 2260 KB Output is correct
10 Correct 3 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 2260 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 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 137 ms 2140 KB Output is correct
22 Correct 116 ms 2156 KB Output is correct
23 Correct 100 ms 2124 KB Output is correct
24 Correct 110 ms 2004 KB Output is correct
25 Correct 118 ms 2132 KB Output is correct
26 Correct 230 ms 1988 KB Output is correct
27 Correct 237 ms 2100 KB Output is correct
28 Correct 228 ms 1956 KB Output is correct
29 Correct 230 ms 2124 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 3 ms 2316 KB Output is correct
32 Correct 3 ms 2260 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 3 ms 2260 KB Output is correct
35 Correct 2 ms 2260 KB Output is correct
36 Correct 3 ms 2260 KB Output is correct
37 Correct 3 ms 2260 KB Output is correct
38 Correct 2 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 1 ms 712 KB Output is correct
3 Correct 2 ms 712 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 712 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 712 KB Output is correct
12 Correct 2 ms 724 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 1 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 2 ms 2264 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
7 Correct 2 ms 2260 KB Output is correct
8 Correct 2 ms 2264 KB Output is correct
9 Correct 2 ms 2260 KB Output is correct
10 Correct 3 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 2260 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 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 137 ms 2140 KB Output is correct
22 Correct 116 ms 2156 KB Output is correct
23 Correct 100 ms 2124 KB Output is correct
24 Correct 110 ms 2004 KB Output is correct
25 Correct 118 ms 2132 KB Output is correct
26 Correct 230 ms 1988 KB Output is correct
27 Correct 237 ms 2100 KB Output is correct
28 Correct 228 ms 1956 KB Output is correct
29 Correct 230 ms 2124 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 3 ms 2316 KB Output is correct
32 Correct 3 ms 2260 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 3 ms 2260 KB Output is correct
35 Correct 2 ms 2260 KB Output is correct
36 Correct 3 ms 2260 KB Output is correct
37 Correct 3 ms 2260 KB Output is correct
38 Correct 2 ms 2260 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 1 ms 712 KB Output is correct
41 Correct 2 ms 712 KB Output is correct
42 Correct 2 ms 716 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 3 ms 712 KB Output is correct
46 Correct 3 ms 724 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 3 ms 724 KB Output is correct
49 Correct 2 ms 712 KB Output is correct
50 Correct 2 ms 724 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 1 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 121 ms 2316 KB Output is correct
60 Correct 108 ms 2328 KB Output is correct
61 Correct 106 ms 2380 KB Output is correct
62 Correct 122 ms 2332 KB Output is correct
63 Correct 122 ms 2316 KB Output is correct
64 Correct 266 ms 2252 KB Output is correct
65 Correct 271 ms 2280 KB Output is correct
66 Correct 263 ms 2384 KB Output is correct
67 Correct 268 ms 2216 KB Output is correct
68 Correct 262 ms 2260 KB Output is correct
69 Correct 120 ms 2316 KB Output is correct
70 Correct 131 ms 2320 KB Output is correct
71 Correct 124 ms 2312 KB Output is correct
72 Correct 124 ms 2312 KB Output is correct
73 Correct 144 ms 2316 KB Output is correct
74 Correct 24 ms 596 KB Output is correct
75 Correct 23 ms 596 KB Output is correct
76 Correct 24 ms 724 KB Output is correct
77 Correct 24 ms 716 KB Output is correct
78 Correct 24 ms 596 KB Output is correct