Submission #14099426
Source Code Expand
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) { lhs = rhs; return true; }
return false;
}
template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) { lhs = rhs; return true; }
return false;
}
struct range {
using itr = int64_t;
struct iterator {
itr i;
constexpr iterator(itr i_): i(i_) { }
constexpr void operator ++ () { ++i; }
constexpr itr operator * () const { return i; }
constexpr bool operator != (iterator x) const { return i != x.i; }
};
const iterator l, r;
constexpr range(itr l_, itr r_): l(l_), r(std::max(l_, r_)) { }
constexpr iterator begin() const { return l; }
constexpr iterator end() const { return r; }
};
struct revrange {
using itr = int64_t;
struct iterator {
itr i;
constexpr iterator(itr i_): i(i_) { }
constexpr void operator ++ () { --i; }
constexpr itr operator * () const { return i; }
constexpr bool operator != (iterator x) const { return i != x.i; }
};
const iterator l, r;
constexpr revrange(itr l_, itr r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
constexpr iterator begin() const { return r; }
constexpr iterator end() const { return l; }
};
template <uint32_t Modulus>
class modular {
public:
using value_type = uint32_t;
using max_type = uint64_t;
static constexpr value_type mod = Modulus;
static constexpr value_type get_mod() { return mod; }
static_assert(mod >= 2, "invalid mod :: smaller than 2");
static_assert(mod < (value_type(1) << 31), "invalid mod :: over 2^31");
template <class T>
static constexpr value_type normalize(T value_) {
if (value_ < 0) {
value_ = -value_;
value_ %= mod;
if (value_ == 0) return 0;
return mod - value_;
}
return value_ % mod;
}
private:
value_type value;
public:
constexpr modular(): value(0) { }
template <class T>
explicit constexpr modular(T value_): value(normalize(value_)) { }
template <class T>
explicit constexpr operator T() { return static_cast<T>(value); }
constexpr value_type get() const { return value; }
constexpr modular operator - () const { return modular(mod - value); }
constexpr modular operator ~ () const { return inverse(); }
constexpr value_type &extract() { return value; }
constexpr modular inverse() const { return power(mod - 2); }
constexpr modular power(max_type exp) const {
modular res(1), mult(*this);
while (exp > 0) {
if (exp & 1) res *= mult;
mult *= mult;
exp >>= 1;
}
return res;
}
constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; }
constexpr modular& operator += (const modular &rhs) {
if ((value += rhs.value) >= mod) value -= mod;
return *this;
}
constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; }
constexpr modular& operator -= (const modular &rhs) {
if ((value += mod - rhs.value) >= mod) value -= mod;
return *this;
}
constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; }
constexpr modular& operator *= (const modular &rhs) {
value = (max_type) value * rhs.value % mod;
return *this;
}
constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; }
constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); }
constexpr bool zero() const { return value == 0; }
constexpr bool operator == (const modular &rhs) const { return value == rhs.value; }
constexpr bool operator != (const modular &rhs) const { return value != rhs.value; }
friend std::ostream& operator << (std::ostream &stream, const modular &rhs) {
return stream << rhs.value;
}
};
using m32 = modular<1000000007>;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;
int main() {
i32 N, A, B;
std::cin >> N >> A >> B;
N += 2;
if (A > B) {
std::swap(A, B);
}
std::vector<std::array<m32, 2>> dp1(N + 1);
for (auto i: range(0, N + 1)) {
for (auto j: range(0, 2)) {
dp1[i][j] = (m32) 0;
}
}
dp1[0][1] = (m32) 1;
for (auto i: range(0, N + 1)) {
{ // extend 0 (greater than or equal to A)
for (auto j: range(A, N + 1)) {
if (i + j <= N) {
dp1[i + j][1] += dp1[i][0];
}
}
}
{ // extend 1 (any length)
for (auto j: range(1, N + 1)) {
if (i + j <= N) {
dp1[i + j][0] += dp1[i][1];
}
}
}
}
std::vector<std::array<std::array<m32, 2>, 2>> dp2(N + 1);
for (auto i: range(0, N + 1)) {
for (auto j: range(0, 2)) {
for (auto k: range(0, 2)) {
dp2[i][j][k] = (m32) 0;
}
}
}
dp2[0][1][0] = (m32) 1;
for (auto i: range(0, N + 1)) {
for (auto k: range(0, 2)) {
{ // extend 0 (less than A)
for (auto j: range(1, A)) {
if (i + j <= N) {
dp2[i + j][1][k] += dp2[i][0][k];
}
}
}
{ // extend 1 (any length)
for (auto j: range(1, N + 1)) {
if (i + j <= N) {
auto len = j;
if (i == 0) --len;
if (i + j == N) --len;
if (len >= B) {
dp2[i + j][0][1] += dp2[i][1][k] * dp1[j][0];
}
else {
dp2[i + j][0][k] += dp2[i][1][k] * dp1[j][0];
}
}
}
}
}
}
std::cout << dp2[N][0][1] << '\n';
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Range Set |
User |
KoD |
Language |
C++ (GCC 9.2.1) |
Score |
800 |
Code Size |
5697 Byte |
Status |
AC |
Exec Time |
133 ms |
Memory |
3752 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
800 / 800 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
All |
00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt |
Case Name |
Status |
Exec Time |
Memory |
00-sample-01.txt |
AC |
2 ms |
3492 KiB |
00-sample-02.txt |
AC |
2 ms |
3472 KiB |
00-sample-03.txt |
AC |
11 ms |
3548 KiB |
01-01.txt |
AC |
2 ms |
3628 KiB |
01-02.txt |
AC |
2 ms |
3432 KiB |
01-03.txt |
AC |
1 ms |
3432 KiB |
01-04.txt |
AC |
2 ms |
3552 KiB |
01-05.txt |
AC |
2 ms |
3580 KiB |
01-06.txt |
AC |
2 ms |
3436 KiB |
01-07.txt |
AC |
2 ms |
3472 KiB |
01-08.txt |
AC |
2 ms |
3420 KiB |
01-09.txt |
AC |
2 ms |
3624 KiB |
01-10.txt |
AC |
2 ms |
3436 KiB |
01-11.txt |
AC |
46 ms |
3492 KiB |
01-12.txt |
AC |
12 ms |
3624 KiB |
01-13.txt |
AC |
18 ms |
3608 KiB |
01-14.txt |
AC |
2 ms |
3600 KiB |
01-15.txt |
AC |
26 ms |
3624 KiB |
01-16.txt |
AC |
118 ms |
3536 KiB |
01-17.txt |
AC |
31 ms |
3544 KiB |
01-18.txt |
AC |
97 ms |
3620 KiB |
01-19.txt |
AC |
30 ms |
3488 KiB |
01-20.txt |
AC |
15 ms |
3528 KiB |
01-21.txt |
AC |
132 ms |
3552 KiB |
01-22.txt |
AC |
117 ms |
3748 KiB |
01-23.txt |
AC |
124 ms |
3668 KiB |
01-24.txt |
AC |
117 ms |
3644 KiB |
01-25.txt |
AC |
127 ms |
3672 KiB |
01-26.txt |
AC |
127 ms |
3748 KiB |
01-27.txt |
AC |
127 ms |
3752 KiB |
01-28.txt |
AC |
128 ms |
3752 KiB |
01-29.txt |
AC |
128 ms |
3716 KiB |
01-30.txt |
AC |
129 ms |
3672 KiB |
01-31.txt |
AC |
128 ms |
3716 KiB |
01-32.txt |
AC |
128 ms |
3612 KiB |
01-33.txt |
AC |
130 ms |
3592 KiB |
01-34.txt |
AC |
114 ms |
3644 KiB |
01-35.txt |
AC |
114 ms |
3752 KiB |
01-36.txt |
AC |
133 ms |
3536 KiB |