結果

問題 No.906 Y字グラフ
ユーザー sifi_border
提出日時 2019-10-11 22:07:51
言語 C++14
(gcc 9.2.0)
結果
AC  
実行時間 4 ms
コード長 4,086 Byte
コンパイル時間 1,504 ms
使用メモリ 3,264 KB
最終ジャッジ日時 2020-01-11 19:03:00

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
1_sample1 AC 0 ms
3,136 KB
2_sample2 AC 0 ms
3,264 KB
3_sample3 AC 0 ms
3,168 KB
4 AC 0 ms
3,168 KB
5 AC 0 ms
3,172 KB
6 AC 0 ms
3,168 KB
7 AC 4 ms
3,252 KB
8 AC 4 ms
3,252 KB
9 AC 0 ms
3,192 KB
10 AC 0 ms
3,196 KB
11 AC 0 ms
3,196 KB
12 AC 0 ms
3,124 KB
13 AC 0 ms
3,132 KB
14 AC 0 ms
3,260 KB
15 AC 0 ms
3,192 KB
16 AC 0 ms
3,196 KB
17 AC 0 ms
3,192 KB
18 AC 0 ms
3,124 KB
19 AC 0 ms
3,196 KB
20 AC 4 ms
3,192 KB
21 AC 0 ms
3,252 KB
22 AC 0 ms
3,260 KB
23 AC 0 ms
3,136 KB
24 AC 0 ms
3,260 KB
25_sample4 AC 0 ms
3,196 KB
26 AC 0 ms
3,252 KB
27 AC 4 ms
3,192 KB
28 AC 4 ms
3,172 KB
29 AC 0 ms
3,188 KB
30 AC 0 ms
3,124 KB
31 AC 4 ms
3,188 KB
32 AC 4 ms
3,176 KB
テストケース一括ダウンロード

ソースコード

diff #
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

template <int p>
struct Modint
{
    int value;

    Modint() : value(0) {}
    Modint(long x) : value(x >= 0 ? x % p : (p + x % p) % p) {}

    inline Modint &operator+=(const Modint &b)
    {
        if ((this->value += b.value) >= p)
            this->value -= p;
        return (*this);
    }
    inline Modint &operator-=(const Modint &b)
    {
        if ((this->value += p - b.value) >= p)
            this->value -= p;
        return (*this);
    }
    inline Modint &operator*=(const Modint &b)
    {
        this->value = (int)((1LL * this->value * b.value) % p);
        return (*this);
    }
    inline Modint &operator/=(const Modint &b)
    {
        (*this) *= b.inverse();
        return (*this);
    }

    Modint operator+(const Modint &b) const { return Modint(*this) += b; }
    Modint operator-(const Modint &b) const { return Modint(*this) -= b; }
    Modint operator*(const Modint &b) const { return Modint(*this) *= b; }
    Modint operator/(const Modint &b) const { return Modint(*this) /= b; }

    inline Modint &operator++(int) { return (*this) += 1; }
    inline Modint &operator--(int) { return (*this) -= 1; }

    inline bool operator==(const Modint &b) const
    {
        return this->value == b.value;
    }
    inline bool operator!=(const Modint &b) const
    {
        return this->value != b.value;
    }
    inline bool operator<(const Modint &b) const
    {
        return this->value < b.value;
    }
    inline bool operator<=(const Modint &b) const
    {
        return this->value <= b.value;
    }
    inline bool operator>(const Modint &b) const
    {
        return this->value > b.value;
    }
    inline bool operator>=(const Modint &b) const
    {
        return this->value >= b.value;
    }

    // requires that "this->value and p are co-prime"
    // a_i * v + a_(i+1) * p = r_i
    // r_i = r_(i+1) * q_(i+1) * r_(i+2)
    // q == 1 (i > 1)
    // reference: https://atcoder.jp/contests/agc026/submissions/2845729
    // (line:93)
    inline Modint inverse() const
    {
        assert(this->value != 0);
        int r0 = p, r1 = this->value, a0 = 0, a1 = 1;
        while (r1)
        {
            int q = r0 / r1;
            r0 -= q * r1;
            swap(r0, r1);
            a0 -= q * a1;
            swap(a0, a1);
        }
        return Modint(a0);
    }

    friend istream &operator>>(istream &is, Modint<p> &a)
    {
        long t;
        is >> t;
        a = Modint<p>(t);
        return is;
    }
    friend ostream &operator<<(ostream &os, const Modint<p> &a)
    {
        return os << a.value;
    }
};

/*
verified @ https://atcoder.jp/contests/abc034/submissions/4316971
*/

const int MOD = 1e9 + 7;

using Int = Modint<MOD>;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    i64 n;
    cin >> n;
    Int tmp = Int(n - 2) * Int(n - 3) / Int(2), ans;
    ans += Int((n - 2) / 2) - Int((n - 1) % 3 == 0);
    tmp -= ans * 3;
    if ((n - 1) % 3 == 0)
    {
        ans++;
        tmp--;
    }
    tmp /= 6;
    ans += tmp;
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}
0