답안 #949334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949334 2024-03-19T06:30:28 Z IBory Boat (APIO16_boat) C++17
100 / 100
257 ms 2128 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll MAX = 1007, MOD = 1E9 + 7;
ll L[MAX], R[MAX], F[MAX], IF[MAX], C[MAX], all[MAX], temp[MAX];
vector<int> S[MAX];

ll Pow(ll N, ll K) {
	ll ret = 1;
	while (K) {
		if (K & 1) ret = ret * N % MOD;
		N = N * N % MOD;
		K >>= 1LL;
	}
	return ret;
}

ll Comb(ll N, ll K) {
	ll ret = IF[K];
	for (ll j = N; j > N - K; --j) ret = (ret * j) % MOD;
	return ret;
}

int main() {
	F[0] = IF[0] = 1;
	for (ll i = 1; i < MAX; ++i) {
		F[i] = F[i - 1] * i % MOD;
		IF[i] = Pow(F[i], MOD - 2);
	}

	ios::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	vector<int> T;
	for (int i = 1; i <= N; ++i) {
		cin >> L[i] >> R[i];
		T.push_back(L[i]);
		T.push_back(R[i] + 1);
	}
	T.push_back(0);

	sort(T.begin(), T.end());
	T.erase(unique(T.begin(), T.end()), T.end());
	for (int i = 1; i <= N; ++i) {
		int l = lower_bound(T.begin(), T.end(), L[i]) - T.begin();
		int r = lower_bound(T.begin(), T.end(), R[i] + 1) - T.begin();
		for (int j = l; j < r; ++j) S[j].push_back(i);
	}

	all[0] = 1;
	for (int i = 1; i + 1 < T.size(); ++i) {
		memset(temp, 0, sizeof(temp));
		ll z = T[i + 1] - T[i];
		ll pv = 0, idx = 0;
		for (int a = 0; a < S[i].size(); ++a) C[a] = Comb(z + a, a + 1);

		for (int a = 0; a < S[i].size(); ++a) {
			while (idx < S[i][a]) pv = (pv + all[idx++]) % MOD;
			for (int b = a; b < S[i].size(); ++b) {
				temp[S[i][b]] = (temp[S[i][b]] + pv * C[b - a]) % MOD;
			}
			pv = 0;
		}
		for (int j = 0; j < MAX; ++j) all[j] = (all[j] + temp[j]) % MOD;
	}

	ll ans = accumulate(all + 1, all + MAX, 0LL) % MOD;
	cout << ans;
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 1; i + 1 < T.size(); ++i) {
      |                  ~~~~~~^~~~~~~~~~
boat.cpp:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int a = 0; a < S[i].size(); ++a) C[a] = Comb(z + a, a + 1);
      |                   ~~^~~~~~~~~~~~~
boat.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for (int a = 0; a < S[i].size(); ++a) {
      |                   ~~^~~~~~~~~~~~~
boat.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    for (int b = a; b < S[i].size(); ++b) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 568 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 564 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 568 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 564 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 99 ms 1468 KB Output is correct
22 Correct 97 ms 1368 KB Output is correct
23 Correct 83 ms 1368 KB Output is correct
24 Correct 97 ms 1372 KB Output is correct
25 Correct 96 ms 1368 KB Output is correct
26 Correct 214 ms 1732 KB Output is correct
27 Correct 219 ms 1768 KB Output is correct
28 Correct 216 ms 1872 KB Output is correct
29 Correct 213 ms 1720 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 4 ms 348 KB Output is correct
37 Correct 3 ms 348 KB Output is correct
38 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 2 ms 500 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 568 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 564 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 99 ms 1468 KB Output is correct
22 Correct 97 ms 1368 KB Output is correct
23 Correct 83 ms 1368 KB Output is correct
24 Correct 97 ms 1372 KB Output is correct
25 Correct 96 ms 1368 KB Output is correct
26 Correct 214 ms 1732 KB Output is correct
27 Correct 219 ms 1768 KB Output is correct
28 Correct 216 ms 1872 KB Output is correct
29 Correct 213 ms 1720 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 4 ms 348 KB Output is correct
37 Correct 3 ms 348 KB Output is correct
38 Correct 3 ms 344 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 3 ms 348 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 2 ms 500 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 107 ms 1372 KB Output is correct
60 Correct 97 ms 1448 KB Output is correct
61 Correct 90 ms 1436 KB Output is correct
62 Correct 109 ms 1628 KB Output is correct
63 Correct 101 ms 1368 KB Output is correct
64 Correct 257 ms 1904 KB Output is correct
65 Correct 244 ms 1900 KB Output is correct
66 Correct 251 ms 1904 KB Output is correct
67 Correct 245 ms 2128 KB Output is correct
68 Correct 245 ms 1884 KB Output is correct
69 Correct 90 ms 1368 KB Output is correct
70 Correct 96 ms 1620 KB Output is correct
71 Correct 95 ms 1372 KB Output is correct
72 Correct 97 ms 1416 KB Output is correct
73 Correct 97 ms 1368 KB Output is correct
74 Correct 21 ms 600 KB Output is correct
75 Correct 20 ms 600 KB Output is correct
76 Correct 21 ms 600 KB Output is correct
77 Correct 22 ms 600 KB Output is correct
78 Correct 22 ms 604 KB Output is correct