# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
255510 |
2020-08-01T06:51:38 Z |
rama_pang |
Boat (APIO16_boat) |
C++14 |
|
427 ms |
4512 KB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int N;
cin >> N;
vector<int> X = {0};
vector<int> A(N + 1), B(N + 1);
for (int i = 1; i <= N; i++) {
cin >> A[i] >> B[i];
X.emplace_back(A[i]);
X.emplace_back(B[i] + 1);
}
sort(begin(X), end(X));
X.erase(unique(begin(X), end(X)), end(X));
for (int i = 1; i <= N; i++) {
A[i] = lower_bound(begin(X), end(X), A[i]) - begin(X);
B[i] = upper_bound(begin(X), end(X), B[i]) - begin(X);
}
const int MOD = 1e9 + 7;
vector<int> inv(N + 1);
inv[0] = 0, inv[1] = 1;
for (int i = 2; i <= N; i++) {
inv[i] = (MOD - 1ll * (MOD / i) * inv[MOD % i] % MOD) % MOD;
}
vector<vector<int>> cmb(N + 1, vector<int>(X.size(), 0));
for (int i = 1; i < (int) X.size(); i++) {
cmb[0][i] = 1;
int x = X[i] - X[i - 1];
for (int j = 1; j <= N; j++) {
cmb[j][i] = 1ll * cmb[j - 1][i] * (x + j - 1) % MOD * inv[j] % MOD;
}
}
vector<vector<int>> dp(N + 1, vector<int>(X.size(), 0));
dp[0] = vector<int>(X.size(), 1);
for (int i = 1; i <= N; i++) {
dp[i][0] = 1;
for (int j = 1; j < (int) X.size(); j++) { // [X[j - 1], X[j])
dp[i][j] = dp[i][j - 1];
for (int k = i, cnt = 0; k > 0; k--) if (A[k] < j && j <= B[k]) {
dp[i][j] += 1ll * cmb[++cnt][j] * dp[k - 1][j - 1] % MOD;
if (dp[i][j] >= MOD) dp[i][j] -= MOD;
}
}
}
cout << ((dp[N][(int) X.size() - 1] - 1 + MOD) % MOD) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
4472 KB |
Output is correct |
2 |
Correct |
253 ms |
4472 KB |
Output is correct |
3 |
Correct |
252 ms |
4472 KB |
Output is correct |
4 |
Correct |
250 ms |
4352 KB |
Output is correct |
5 |
Correct |
248 ms |
4376 KB |
Output is correct |
6 |
Correct |
163 ms |
4352 KB |
Output is correct |
7 |
Correct |
146 ms |
4352 KB |
Output is correct |
8 |
Correct |
160 ms |
4352 KB |
Output is correct |
9 |
Correct |
155 ms |
4472 KB |
Output is correct |
10 |
Correct |
149 ms |
4472 KB |
Output is correct |
11 |
Correct |
150 ms |
4512 KB |
Output is correct |
12 |
Correct |
153 ms |
4472 KB |
Output is correct |
13 |
Correct |
146 ms |
4352 KB |
Output is correct |
14 |
Correct |
138 ms |
4368 KB |
Output is correct |
15 |
Correct |
150 ms |
4472 KB |
Output is correct |
16 |
Correct |
51 ms |
1024 KB |
Output is correct |
17 |
Correct |
55 ms |
1152 KB |
Output is correct |
18 |
Correct |
52 ms |
1152 KB |
Output is correct |
19 |
Correct |
55 ms |
1200 KB |
Output is correct |
20 |
Correct |
54 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
4472 KB |
Output is correct |
2 |
Correct |
253 ms |
4472 KB |
Output is correct |
3 |
Correct |
252 ms |
4472 KB |
Output is correct |
4 |
Correct |
250 ms |
4352 KB |
Output is correct |
5 |
Correct |
248 ms |
4376 KB |
Output is correct |
6 |
Correct |
163 ms |
4352 KB |
Output is correct |
7 |
Correct |
146 ms |
4352 KB |
Output is correct |
8 |
Correct |
160 ms |
4352 KB |
Output is correct |
9 |
Correct |
155 ms |
4472 KB |
Output is correct |
10 |
Correct |
149 ms |
4472 KB |
Output is correct |
11 |
Correct |
150 ms |
4512 KB |
Output is correct |
12 |
Correct |
153 ms |
4472 KB |
Output is correct |
13 |
Correct |
146 ms |
4352 KB |
Output is correct |
14 |
Correct |
138 ms |
4368 KB |
Output is correct |
15 |
Correct |
150 ms |
4472 KB |
Output is correct |
16 |
Correct |
51 ms |
1024 KB |
Output is correct |
17 |
Correct |
55 ms |
1152 KB |
Output is correct |
18 |
Correct |
52 ms |
1152 KB |
Output is correct |
19 |
Correct |
55 ms |
1200 KB |
Output is correct |
20 |
Correct |
54 ms |
1152 KB |
Output is correct |
21 |
Correct |
331 ms |
3968 KB |
Output is correct |
22 |
Correct |
343 ms |
4088 KB |
Output is correct |
23 |
Correct |
316 ms |
3968 KB |
Output is correct |
24 |
Correct |
331 ms |
3968 KB |
Output is correct |
25 |
Correct |
334 ms |
3968 KB |
Output is correct |
26 |
Correct |
338 ms |
3896 KB |
Output is correct |
27 |
Correct |
349 ms |
3840 KB |
Output is correct |
28 |
Correct |
352 ms |
3960 KB |
Output is correct |
29 |
Correct |
348 ms |
3840 KB |
Output is correct |
30 |
Correct |
163 ms |
4352 KB |
Output is correct |
31 |
Correct |
152 ms |
4352 KB |
Output is correct |
32 |
Correct |
151 ms |
4472 KB |
Output is correct |
33 |
Correct |
152 ms |
4352 KB |
Output is correct |
34 |
Correct |
148 ms |
4352 KB |
Output is correct |
35 |
Correct |
258 ms |
4472 KB |
Output is correct |
36 |
Correct |
256 ms |
4352 KB |
Output is correct |
37 |
Correct |
256 ms |
4352 KB |
Output is correct |
38 |
Correct |
252 ms |
4472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
4 ms |
512 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
4472 KB |
Output is correct |
2 |
Correct |
253 ms |
4472 KB |
Output is correct |
3 |
Correct |
252 ms |
4472 KB |
Output is correct |
4 |
Correct |
250 ms |
4352 KB |
Output is correct |
5 |
Correct |
248 ms |
4376 KB |
Output is correct |
6 |
Correct |
163 ms |
4352 KB |
Output is correct |
7 |
Correct |
146 ms |
4352 KB |
Output is correct |
8 |
Correct |
160 ms |
4352 KB |
Output is correct |
9 |
Correct |
155 ms |
4472 KB |
Output is correct |
10 |
Correct |
149 ms |
4472 KB |
Output is correct |
11 |
Correct |
150 ms |
4512 KB |
Output is correct |
12 |
Correct |
153 ms |
4472 KB |
Output is correct |
13 |
Correct |
146 ms |
4352 KB |
Output is correct |
14 |
Correct |
138 ms |
4368 KB |
Output is correct |
15 |
Correct |
150 ms |
4472 KB |
Output is correct |
16 |
Correct |
51 ms |
1024 KB |
Output is correct |
17 |
Correct |
55 ms |
1152 KB |
Output is correct |
18 |
Correct |
52 ms |
1152 KB |
Output is correct |
19 |
Correct |
55 ms |
1200 KB |
Output is correct |
20 |
Correct |
54 ms |
1152 KB |
Output is correct |
21 |
Correct |
331 ms |
3968 KB |
Output is correct |
22 |
Correct |
343 ms |
4088 KB |
Output is correct |
23 |
Correct |
316 ms |
3968 KB |
Output is correct |
24 |
Correct |
331 ms |
3968 KB |
Output is correct |
25 |
Correct |
334 ms |
3968 KB |
Output is correct |
26 |
Correct |
338 ms |
3896 KB |
Output is correct |
27 |
Correct |
349 ms |
3840 KB |
Output is correct |
28 |
Correct |
352 ms |
3960 KB |
Output is correct |
29 |
Correct |
348 ms |
3840 KB |
Output is correct |
30 |
Correct |
163 ms |
4352 KB |
Output is correct |
31 |
Correct |
152 ms |
4352 KB |
Output is correct |
32 |
Correct |
151 ms |
4472 KB |
Output is correct |
33 |
Correct |
152 ms |
4352 KB |
Output is correct |
34 |
Correct |
148 ms |
4352 KB |
Output is correct |
35 |
Correct |
258 ms |
4472 KB |
Output is correct |
36 |
Correct |
256 ms |
4352 KB |
Output is correct |
37 |
Correct |
256 ms |
4352 KB |
Output is correct |
38 |
Correct |
252 ms |
4472 KB |
Output is correct |
39 |
Correct |
4 ms |
512 KB |
Output is correct |
40 |
Correct |
4 ms |
512 KB |
Output is correct |
41 |
Correct |
4 ms |
512 KB |
Output is correct |
42 |
Correct |
4 ms |
512 KB |
Output is correct |
43 |
Correct |
3 ms |
512 KB |
Output is correct |
44 |
Correct |
4 ms |
640 KB |
Output is correct |
45 |
Correct |
4 ms |
512 KB |
Output is correct |
46 |
Correct |
4 ms |
512 KB |
Output is correct |
47 |
Correct |
4 ms |
512 KB |
Output is correct |
48 |
Correct |
5 ms |
512 KB |
Output is correct |
49 |
Correct |
4 ms |
512 KB |
Output is correct |
50 |
Correct |
3 ms |
512 KB |
Output is correct |
51 |
Correct |
4 ms |
512 KB |
Output is correct |
52 |
Correct |
4 ms |
512 KB |
Output is correct |
53 |
Correct |
4 ms |
512 KB |
Output is correct |
54 |
Correct |
2 ms |
384 KB |
Output is correct |
55 |
Correct |
4 ms |
512 KB |
Output is correct |
56 |
Correct |
2 ms |
384 KB |
Output is correct |
57 |
Correct |
2 ms |
384 KB |
Output is correct |
58 |
Correct |
2 ms |
384 KB |
Output is correct |
59 |
Correct |
369 ms |
4352 KB |
Output is correct |
60 |
Correct |
364 ms |
4372 KB |
Output is correct |
61 |
Correct |
359 ms |
4372 KB |
Output is correct |
62 |
Correct |
365 ms |
4472 KB |
Output is correct |
63 |
Correct |
361 ms |
4372 KB |
Output is correct |
64 |
Correct |
427 ms |
4472 KB |
Output is correct |
65 |
Correct |
394 ms |
4472 KB |
Output is correct |
66 |
Correct |
399 ms |
4376 KB |
Output is correct |
67 |
Correct |
380 ms |
4352 KB |
Output is correct |
68 |
Correct |
407 ms |
4276 KB |
Output is correct |
69 |
Correct |
360 ms |
4372 KB |
Output is correct |
70 |
Correct |
392 ms |
4352 KB |
Output is correct |
71 |
Correct |
363 ms |
4476 KB |
Output is correct |
72 |
Correct |
368 ms |
4352 KB |
Output is correct |
73 |
Correct |
363 ms |
4472 KB |
Output is correct |
74 |
Correct |
82 ms |
1152 KB |
Output is correct |
75 |
Correct |
91 ms |
1152 KB |
Output is correct |
76 |
Correct |
82 ms |
1152 KB |
Output is correct |
77 |
Correct |
82 ms |
1152 KB |
Output is correct |
78 |
Correct |
78 ms |
1152 KB |
Output is correct |