結果
問題 | No.906 Y字グラフ |
ユーザー | polylogK |
提出日時 | 2019-10-11 22:00:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,993 bytes |
コンパイル時間 | 1,723 ms |
コンパイル使用メモリ | 167,040 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-05-04 01:36:52 |
合計ジャッジ時間 | 2,801 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | WA | - |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | WA | - |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | WA | - |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | WA | - |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | WA | - |
testcase_31 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } template <std::uint_fast64_t Modulus> class modint { using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using i64 = std::int_fast64_t; public: u64 a; constexpr modint() noexcept : a(0) {} constexpr modint(const u64 & x) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } const modint inverse() const { i64 x = a, b = Modulus, u = 1, v = 0; while(b > 0) { auto t = x / b; std::swap(x -= t * b, b); std::swap(u -= t * v, v); } return modint(u); } const modint pow(i64 k) const { return modint(*this) ^ k; } static u64 mod() { return Modulus; } constexpr modint & operator+=(const modint & rhs) noexcept { a += rhs.a; if (a >= Modulus) a -= Modulus; return *this; } constexpr modint & operator-=(const modint & rhs) noexcept { if (a < rhs.a) a += Modulus; a -= rhs.a; return *this; } constexpr modint & operator*=(const modint & rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint & operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) (*this) *= rhs; rhs *= rhs; exp /= 2; } return *this; } constexpr modint & operator^=(u64 k) noexcept { auto b = modint(1); while(k) { if(k & 1) b = b * (*this); (*this) *= (*this); k >>= 1; } return (*this) = b; } constexpr modint & operator=(const modint & rhs) noexcept { a = rhs.a; return (*this); } constexpr modint operator+(const modint & rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint & rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint & rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint & rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint operator^(const u64 & k) const noexcept { return modint(*this) ^= k; } constexpr modint operator-() const noexcept { return modint(Modulus - a); } constexpr modint operator++() noexcept { return (*this) = modint(*this) + 1; } constexpr modint operator--() noexcept { return (*this) = modint(*this) - 1; } const bool operator==(const modint & rhs) const noexcept { return a == rhs.a; }; const bool operator!=(const modint & rhs) const noexcept { return a != rhs.a; }; const bool operator<=(const modint & rhs) const noexcept { return a <= rhs.a; }; const bool operator>=(const modint & rhs) const noexcept { return a >= rhs.a; }; const bool operator<(const modint & rhs) const noexcept { return a < rhs.a; }; const bool operator>(const modint & rhs) const noexcept { return a > rhs.a; }; explicit operator bool() const { return a; } explicit operator u32() const { return a; } friend std::ostream & operator<<(std::ostream & os, const modint & p) { return os << p.a; } friend std::istream & operator>>(std::istream & is, modint & p) { u64 t; is >> t; p = modint(t); return is; } }; using mint = modint<(int)(1e9 + 7)>; int main() { i64 n; scanf("%lld", &n); n -= 4; if(n < 3) { printf("1\n"); return 0; } auto calc_even = [&](i64 n) { i64 I = n / 6; mint A = (mint)(I + 1) * n / 2; mint B = (mint)I * (I + 1) * 3 / 2; return A - B; }; auto calc_odd = [&](i64 n) { i64 I = (n - 1) / 6; mint A = (mint)(I + 1) * (n - 1) / 2; mint B = (mint)I * (I + 1) * 3 / 2; return A - B; }; mint ans = (n + 1) / 3LL + 1; if(n & 1) { ans += calc_odd(n) + calc_even(n - 3); } else { ans += calc_even(n) + calc_odd(n - 3); } printf("%lld\n", ans.value()); return 0; }