# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
969439 |
2024-04-25T07:06:45 Z |
kilkuwu |
Boat (APIO16_boat) |
C++17 |
|
228 ms |
6484 KB |
#include <bits/stdc++.h>
#define nl '\n'
#ifdef LOCAL
#include "template/debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif
template <int md>
struct Modular {
int v;
constexpr Modular() : v(0) {}
template <typename T>
static inline int normalize(const T& x) {
int res = -md <= x && x < md ? static_cast<int>(x) : static_cast<int>(x % md);
return res + (res < 0) * md;
}
static constexpr int mod() {
return md;
}
template <typename U>
Modular(const U& x) : v(normalize(x)) {}
const int& operator()() const { return v; }
template <typename U>
explicit operator U() const {
return static_cast<U>(v);
}
using M = Modular;
constexpr static inline M _raw(int x) {
static_assert(x >= 0 && x < md);
M res;
res.v = x;
return res;
}
template <typename U>
friend std::enable_if_t<std::is_integral_v<U>, M> power(M b, U e) {
assert(e >= 0);
M ans = 1;
while (e) {
if (e & 1) ans *= b;
b *= b;
e >>= 1;
}
return ans;
}
M inv() const {
M res = power(*this, md - 2);
return res;
}
M& operator+=(const M& y) { return v += y.v, v -= (v >= md) * md, *this; }
M& operator-=(const M& y) { return v -= y.v, v += (v < 0) * md, *this; }
M& operator*=(const M& y) { return v = (int64_t) v * y.v % md, *this; }
M& operator/=(const M& y) { return *this *= y.inv(); }
M& operator++() { return *this += _raw(1); }
M& operator--() { return *this -= _raw(1); }
M operator++(int) {
M res(*this);
return *this += _raw(1), res;
}
M operator--(int) {
M res(*this);
return *this -= _raw(1), res;
}
M operator-() const { return M(-v); }
friend bool operator==(const M& x, const M& y) { return x.v == y.v; }
friend bool operator<(const M& x, const M& y) { return x.v < y.v; }
friend bool operator>(const M& x, const M& y) { return x.v > y.v; }
friend bool operator<=(const M& x, const M& y) { return x.v <= y.v; }
friend bool operator>=(const M& x, const M& y) { return x.v >= y.v; }
friend bool operator!=(const M& x, const M& y) { return x.v != y.v; }
template <typename Istream>
friend Istream& operator>>(Istream& is, M& y) {
int64_t x;
is >> x;
y.v = y.normalize(x);
return is;
}
template <typename Ostream>
friend Ostream& operator<<(Ostream& os, const M& y) {
return os << y.v;
}
friend M operator+(const M& x, const M& y) { return M(x) += y; }
friend M operator-(const M& x, const M& y) { return M(x) -= y; }
friend M operator*(const M& x, const M& y) { return M(x) *= y; }
friend M operator/(const M& x, const M& y) { return M(x) /= y; }
};
constexpr int md = 1e9 + 7;
using Mint = Modular<md>;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n), b(n);
for (int i = 0; i < n; i++) std::cin >> a[i] >> b[i], b[i]++;
std::vector<int> vals(a.begin(), a.end());
vals.insert(vals.end(), b.begin(), b.end());
std::sort(vals.begin(), vals.end());
vals.erase(std::unique(vals.begin(), vals.end()), vals.end());
dbg(vals);
int num_segments = vals.size() - 1;
for (int i = 0; i < n; i++) {
a[i] = std::lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();
b[i] = std::lower_bound(vals.begin(), vals.end(), b[i]) - vals.begin();
dbg(a[i], b[i]);
}
std::vector<std::vector<Mint>> prepared(num_segments, std::vector<Mint>(n + 1));
for (int i = 0; i < num_segments; i++) {
int len = vals[i + 1] - vals[i] - 1;
prepared[i][0] = 1;
for (int j = 0; j < n; j++) {
prepared[i][j + 1] = prepared[i][j] * (len - j) / (j + 1);
}
for (int j = 0; j < n; j++) {
prepared[i][j + 1] += prepared[i][j];
}
}
std::vector<std::vector<Mint>> dp(n + 1, std::vector<Mint>(num_segments + 1));
std::vector<std::vector<Mint>> ff(n + 1, std::vector<Mint>(num_segments + 1));
dp[n].back() = 1;
for (int j = 0; j <= num_segments; j++) {
ff[n][j] = 1;
}
Mint ans = 0;
for (int i = n - 1; i >= 0; i--) {
for (int j = num_segments - 1; j >= 0; j--) {
if (a[i] <= j && j < b[i]) {
int cnt = 0;
for (int k = i; k < n; k++) {
cnt += a[k] <= j && j < b[k];
int rem = cnt - 1;
Mint mul = prepared[j][rem];
dbg(i, j, k, mul, rem, ff[k + 1][j + 1], mul * ff[k + 1][j + 1]);
dp[i][j] += ff[k + 1][j + 1] * mul;
}
}
ans += dp[i][j];
dbg(i, j, dp[i][j]);
ff[i][j] = ff[i][j + 1] + dp[i][j];
}
}
std::cout << ans << nl;
// 4
// 4 7
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
6276 KB |
Output is correct |
2 |
Correct |
79 ms |
6272 KB |
Output is correct |
3 |
Correct |
78 ms |
6228 KB |
Output is correct |
4 |
Correct |
78 ms |
6276 KB |
Output is correct |
5 |
Correct |
78 ms |
6224 KB |
Output is correct |
6 |
Correct |
78 ms |
6292 KB |
Output is correct |
7 |
Correct |
77 ms |
6224 KB |
Output is correct |
8 |
Correct |
79 ms |
6292 KB |
Output is correct |
9 |
Correct |
78 ms |
6484 KB |
Output is correct |
10 |
Correct |
78 ms |
6228 KB |
Output is correct |
11 |
Correct |
79 ms |
6272 KB |
Output is correct |
12 |
Correct |
78 ms |
6228 KB |
Output is correct |
13 |
Correct |
78 ms |
6284 KB |
Output is correct |
14 |
Correct |
78 ms |
6296 KB |
Output is correct |
15 |
Correct |
77 ms |
6288 KB |
Output is correct |
16 |
Correct |
15 ms |
1332 KB |
Output is correct |
17 |
Correct |
16 ms |
1616 KB |
Output is correct |
18 |
Correct |
15 ms |
1372 KB |
Output is correct |
19 |
Correct |
16 ms |
1608 KB |
Output is correct |
20 |
Correct |
15 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
6276 KB |
Output is correct |
2 |
Correct |
79 ms |
6272 KB |
Output is correct |
3 |
Correct |
78 ms |
6228 KB |
Output is correct |
4 |
Correct |
78 ms |
6276 KB |
Output is correct |
5 |
Correct |
78 ms |
6224 KB |
Output is correct |
6 |
Correct |
78 ms |
6292 KB |
Output is correct |
7 |
Correct |
77 ms |
6224 KB |
Output is correct |
8 |
Correct |
79 ms |
6292 KB |
Output is correct |
9 |
Correct |
78 ms |
6484 KB |
Output is correct |
10 |
Correct |
78 ms |
6228 KB |
Output is correct |
11 |
Correct |
79 ms |
6272 KB |
Output is correct |
12 |
Correct |
78 ms |
6228 KB |
Output is correct |
13 |
Correct |
78 ms |
6284 KB |
Output is correct |
14 |
Correct |
78 ms |
6296 KB |
Output is correct |
15 |
Correct |
77 ms |
6288 KB |
Output is correct |
16 |
Correct |
15 ms |
1332 KB |
Output is correct |
17 |
Correct |
16 ms |
1616 KB |
Output is correct |
18 |
Correct |
15 ms |
1372 KB |
Output is correct |
19 |
Correct |
16 ms |
1608 KB |
Output is correct |
20 |
Correct |
15 ms |
1372 KB |
Output is correct |
21 |
Incorrect |
228 ms |
5880 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
6276 KB |
Output is correct |
2 |
Correct |
79 ms |
6272 KB |
Output is correct |
3 |
Correct |
78 ms |
6228 KB |
Output is correct |
4 |
Correct |
78 ms |
6276 KB |
Output is correct |
5 |
Correct |
78 ms |
6224 KB |
Output is correct |
6 |
Correct |
78 ms |
6292 KB |
Output is correct |
7 |
Correct |
77 ms |
6224 KB |
Output is correct |
8 |
Correct |
79 ms |
6292 KB |
Output is correct |
9 |
Correct |
78 ms |
6484 KB |
Output is correct |
10 |
Correct |
78 ms |
6228 KB |
Output is correct |
11 |
Correct |
79 ms |
6272 KB |
Output is correct |
12 |
Correct |
78 ms |
6228 KB |
Output is correct |
13 |
Correct |
78 ms |
6284 KB |
Output is correct |
14 |
Correct |
78 ms |
6296 KB |
Output is correct |
15 |
Correct |
77 ms |
6288 KB |
Output is correct |
16 |
Correct |
15 ms |
1332 KB |
Output is correct |
17 |
Correct |
16 ms |
1616 KB |
Output is correct |
18 |
Correct |
15 ms |
1372 KB |
Output is correct |
19 |
Correct |
16 ms |
1608 KB |
Output is correct |
20 |
Correct |
15 ms |
1372 KB |
Output is correct |
21 |
Incorrect |
228 ms |
5880 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |