# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
376783 |
2021-03-12T03:49:06 Z |
KoD |
Boat (APIO16_boat) |
C++17 |
|
607 ms |
6892 KB |
#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
constexpr int MOD = 1000000007;
struct Fp {
int val;
Fp(const int val = 0): val(((val % MOD) + MOD) % MOD) { }
Fp& operator += (const Fp &other) {
if ((val += other.val) >= MOD) val -= MOD;
return *this;
}
Fp operator + (const Fp &other) const {
return Fp(*this) += other;
}
Fp& operator -= (const Fp &other) {
if ((val += MOD - other.val) >= MOD) val -= MOD;
return *this;
}
Fp operator - (const Fp &other) const {
return Fp(*this) -= other;
}
Fp& operator *= (const Fp &other) {
val = (long long) val * other.val % MOD;
return *this;
}
Fp operator * (const Fp &other) const {
return Fp(*this) *= other;
}
Fp& operator /= (const Fp &other) {
return *this *= other.inv();
}
Fp operator / (const Fp &other) const {
return Fp(*this) /= other;
}
Fp inv() const {
return pow(MOD - 2);
}
Fp pow(int e) const {
Fp ret(1), mult(*this);
while (e > 0) {
if (e & 1) ret *= mult;
mult *= mult;
e >>= 1;
}
return ret;
}
};
int main() {
int N;
std::cin >> N;
Vec<int> A(N), B(N);
Vec<int> cmp;
cmp.reserve(2 * N);
for (int i = 0; i < N; ++i) {
std::cin >> A[i] >> B[i];
B[i] += 1;
cmp.push_back(A[i]);
cmp.push_back(B[i]);
}
std::sort(cmp.begin(), cmp.end());
cmp.erase(std::unique(cmp.begin(), cmp.end()), cmp.end());
for (auto &x: A) {
x = std::lower_bound(cmp.begin(), cmp.end(), x) - cmp.begin();
}
for (auto &x: B) {
x = std::lower_bound(cmp.begin(), cmp.end(), x) - cmp.begin();
}
const auto size = (int) cmp.size() - 1;
Vec<Vec<Fp>> coeff(size, Vec<Fp>(N + 1));
for (int k = 0; k < size; ++k) {
Fp val(cmp[k + 1] - cmp[k]);
for (int j = 1; j <= N; ++j) {
if (cmp[k + 1] - cmp[k] < j) {
break;
}
coeff[k][j] = val;
val *= Fp(cmp[k + 1] - cmp[k] - j);
val /= Fp(j + 1);
}
}
Vec<Vec<Fp>> dp(size, Vec<Fp>(1));
for (int k = 0; k < size; ++k) {
dp[k][0] = Fp(1);
}
Fp ans;
for (int i = 0; i < N; ++i) {
Vec<Vec<Fp>> next(size, Vec<Fp>(i + 2));
Fp sum;
for (int k = 0; k < size; ++k) {
next[k][0] += sum;
for (int j = 0; j <= i; ++j) {
if (dp[k][j].val == 0) {
continue;
}
next[k][j] += dp[k][j];
if (A[i] <= k && k < B[i]) {
next[k][j + 1] += dp[k][j];
const auto end = dp[k][j] * coeff[k][j + 1];
ans += end;
sum += end;
}
}
}
dp = std::move(next);
}
std::cout << ans.val << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
6764 KB |
Output is correct |
2 |
Correct |
296 ms |
6764 KB |
Output is correct |
3 |
Correct |
299 ms |
6636 KB |
Output is correct |
4 |
Correct |
300 ms |
6636 KB |
Output is correct |
5 |
Correct |
298 ms |
6636 KB |
Output is correct |
6 |
Correct |
297 ms |
6892 KB |
Output is correct |
7 |
Correct |
293 ms |
6764 KB |
Output is correct |
8 |
Correct |
301 ms |
6636 KB |
Output is correct |
9 |
Correct |
299 ms |
6788 KB |
Output is correct |
10 |
Correct |
297 ms |
6764 KB |
Output is correct |
11 |
Correct |
303 ms |
6696 KB |
Output is correct |
12 |
Correct |
295 ms |
6636 KB |
Output is correct |
13 |
Correct |
299 ms |
6764 KB |
Output is correct |
14 |
Correct |
297 ms |
6636 KB |
Output is correct |
15 |
Correct |
308 ms |
6636 KB |
Output is correct |
16 |
Correct |
53 ms |
1720 KB |
Output is correct |
17 |
Correct |
58 ms |
1772 KB |
Output is correct |
18 |
Correct |
55 ms |
1772 KB |
Output is correct |
19 |
Correct |
57 ms |
1900 KB |
Output is correct |
20 |
Correct |
56 ms |
1772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
6764 KB |
Output is correct |
2 |
Correct |
296 ms |
6764 KB |
Output is correct |
3 |
Correct |
299 ms |
6636 KB |
Output is correct |
4 |
Correct |
300 ms |
6636 KB |
Output is correct |
5 |
Correct |
298 ms |
6636 KB |
Output is correct |
6 |
Correct |
297 ms |
6892 KB |
Output is correct |
7 |
Correct |
293 ms |
6764 KB |
Output is correct |
8 |
Correct |
301 ms |
6636 KB |
Output is correct |
9 |
Correct |
299 ms |
6788 KB |
Output is correct |
10 |
Correct |
297 ms |
6764 KB |
Output is correct |
11 |
Correct |
303 ms |
6696 KB |
Output is correct |
12 |
Correct |
295 ms |
6636 KB |
Output is correct |
13 |
Correct |
299 ms |
6764 KB |
Output is correct |
14 |
Correct |
297 ms |
6636 KB |
Output is correct |
15 |
Correct |
308 ms |
6636 KB |
Output is correct |
16 |
Correct |
53 ms |
1720 KB |
Output is correct |
17 |
Correct |
58 ms |
1772 KB |
Output is correct |
18 |
Correct |
55 ms |
1772 KB |
Output is correct |
19 |
Correct |
57 ms |
1900 KB |
Output is correct |
20 |
Correct |
56 ms |
1772 KB |
Output is correct |
21 |
Correct |
344 ms |
6252 KB |
Output is correct |
22 |
Correct |
350 ms |
6252 KB |
Output is correct |
23 |
Correct |
320 ms |
6252 KB |
Output is correct |
24 |
Correct |
333 ms |
6124 KB |
Output is correct |
25 |
Correct |
338 ms |
6124 KB |
Output is correct |
26 |
Correct |
432 ms |
6124 KB |
Output is correct |
27 |
Correct |
443 ms |
6072 KB |
Output is correct |
28 |
Correct |
449 ms |
5944 KB |
Output is correct |
29 |
Correct |
439 ms |
5932 KB |
Output is correct |
30 |
Correct |
289 ms |
6636 KB |
Output is correct |
31 |
Correct |
295 ms |
6764 KB |
Output is correct |
32 |
Correct |
301 ms |
6636 KB |
Output is correct |
33 |
Correct |
289 ms |
6636 KB |
Output is correct |
34 |
Correct |
303 ms |
6636 KB |
Output is correct |
35 |
Correct |
293 ms |
6636 KB |
Output is correct |
36 |
Correct |
300 ms |
6636 KB |
Output is correct |
37 |
Correct |
296 ms |
6832 KB |
Output is correct |
38 |
Correct |
301 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
620 KB |
Output is correct |
2 |
Correct |
8 ms |
620 KB |
Output is correct |
3 |
Correct |
11 ms |
620 KB |
Output is correct |
4 |
Correct |
11 ms |
620 KB |
Output is correct |
5 |
Correct |
9 ms |
620 KB |
Output is correct |
6 |
Correct |
10 ms |
620 KB |
Output is correct |
7 |
Correct |
10 ms |
620 KB |
Output is correct |
8 |
Correct |
12 ms |
620 KB |
Output is correct |
9 |
Correct |
10 ms |
620 KB |
Output is correct |
10 |
Correct |
10 ms |
620 KB |
Output is correct |
11 |
Correct |
9 ms |
620 KB |
Output is correct |
12 |
Correct |
9 ms |
620 KB |
Output is correct |
13 |
Correct |
9 ms |
620 KB |
Output is correct |
14 |
Correct |
9 ms |
620 KB |
Output is correct |
15 |
Correct |
9 ms |
620 KB |
Output is correct |
16 |
Correct |
5 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
492 KB |
Output is correct |
18 |
Correct |
5 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
492 KB |
Output is correct |
20 |
Correct |
5 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
6764 KB |
Output is correct |
2 |
Correct |
296 ms |
6764 KB |
Output is correct |
3 |
Correct |
299 ms |
6636 KB |
Output is correct |
4 |
Correct |
300 ms |
6636 KB |
Output is correct |
5 |
Correct |
298 ms |
6636 KB |
Output is correct |
6 |
Correct |
297 ms |
6892 KB |
Output is correct |
7 |
Correct |
293 ms |
6764 KB |
Output is correct |
8 |
Correct |
301 ms |
6636 KB |
Output is correct |
9 |
Correct |
299 ms |
6788 KB |
Output is correct |
10 |
Correct |
297 ms |
6764 KB |
Output is correct |
11 |
Correct |
303 ms |
6696 KB |
Output is correct |
12 |
Correct |
295 ms |
6636 KB |
Output is correct |
13 |
Correct |
299 ms |
6764 KB |
Output is correct |
14 |
Correct |
297 ms |
6636 KB |
Output is correct |
15 |
Correct |
308 ms |
6636 KB |
Output is correct |
16 |
Correct |
53 ms |
1720 KB |
Output is correct |
17 |
Correct |
58 ms |
1772 KB |
Output is correct |
18 |
Correct |
55 ms |
1772 KB |
Output is correct |
19 |
Correct |
57 ms |
1900 KB |
Output is correct |
20 |
Correct |
56 ms |
1772 KB |
Output is correct |
21 |
Correct |
344 ms |
6252 KB |
Output is correct |
22 |
Correct |
350 ms |
6252 KB |
Output is correct |
23 |
Correct |
320 ms |
6252 KB |
Output is correct |
24 |
Correct |
333 ms |
6124 KB |
Output is correct |
25 |
Correct |
338 ms |
6124 KB |
Output is correct |
26 |
Correct |
432 ms |
6124 KB |
Output is correct |
27 |
Correct |
443 ms |
6072 KB |
Output is correct |
28 |
Correct |
449 ms |
5944 KB |
Output is correct |
29 |
Correct |
439 ms |
5932 KB |
Output is correct |
30 |
Correct |
289 ms |
6636 KB |
Output is correct |
31 |
Correct |
295 ms |
6764 KB |
Output is correct |
32 |
Correct |
301 ms |
6636 KB |
Output is correct |
33 |
Correct |
289 ms |
6636 KB |
Output is correct |
34 |
Correct |
303 ms |
6636 KB |
Output is correct |
35 |
Correct |
293 ms |
6636 KB |
Output is correct |
36 |
Correct |
300 ms |
6636 KB |
Output is correct |
37 |
Correct |
296 ms |
6832 KB |
Output is correct |
38 |
Correct |
301 ms |
6636 KB |
Output is correct |
39 |
Correct |
9 ms |
620 KB |
Output is correct |
40 |
Correct |
8 ms |
620 KB |
Output is correct |
41 |
Correct |
11 ms |
620 KB |
Output is correct |
42 |
Correct |
11 ms |
620 KB |
Output is correct |
43 |
Correct |
9 ms |
620 KB |
Output is correct |
44 |
Correct |
10 ms |
620 KB |
Output is correct |
45 |
Correct |
10 ms |
620 KB |
Output is correct |
46 |
Correct |
12 ms |
620 KB |
Output is correct |
47 |
Correct |
10 ms |
620 KB |
Output is correct |
48 |
Correct |
10 ms |
620 KB |
Output is correct |
49 |
Correct |
9 ms |
620 KB |
Output is correct |
50 |
Correct |
9 ms |
620 KB |
Output is correct |
51 |
Correct |
9 ms |
620 KB |
Output is correct |
52 |
Correct |
9 ms |
620 KB |
Output is correct |
53 |
Correct |
9 ms |
620 KB |
Output is correct |
54 |
Correct |
5 ms |
492 KB |
Output is correct |
55 |
Correct |
5 ms |
492 KB |
Output is correct |
56 |
Correct |
5 ms |
492 KB |
Output is correct |
57 |
Correct |
5 ms |
492 KB |
Output is correct |
58 |
Correct |
5 ms |
492 KB |
Output is correct |
59 |
Correct |
469 ms |
6764 KB |
Output is correct |
60 |
Correct |
457 ms |
6892 KB |
Output is correct |
61 |
Correct |
458 ms |
6764 KB |
Output is correct |
62 |
Correct |
471 ms |
6764 KB |
Output is correct |
63 |
Correct |
463 ms |
6636 KB |
Output is correct |
64 |
Correct |
595 ms |
6764 KB |
Output is correct |
65 |
Correct |
593 ms |
6892 KB |
Output is correct |
66 |
Correct |
592 ms |
6636 KB |
Output is correct |
67 |
Correct |
597 ms |
6636 KB |
Output is correct |
68 |
Correct |
607 ms |
6724 KB |
Output is correct |
69 |
Correct |
465 ms |
6636 KB |
Output is correct |
70 |
Correct |
453 ms |
6636 KB |
Output is correct |
71 |
Correct |
459 ms |
6892 KB |
Output is correct |
72 |
Correct |
463 ms |
6764 KB |
Output is correct |
73 |
Correct |
455 ms |
6636 KB |
Output is correct |
74 |
Correct |
77 ms |
1772 KB |
Output is correct |
75 |
Correct |
78 ms |
1920 KB |
Output is correct |
76 |
Correct |
79 ms |
1772 KB |
Output is correct |
77 |
Correct |
78 ms |
1772 KB |
Output is correct |
78 |
Correct |
78 ms |
1772 KB |
Output is correct |