結果

問題 No.906 Y字グラフ
ユーザー kcvlexkcvlex
提出日時 2019-10-11 22:01:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,861 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 167,748 KB
実行使用メモリ 18,860 KB
最終ジャッジ日時 2023-08-16 17:50:28
合計ジャッジ時間 3,473 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
18,552 KB
testcase_01 AC 18 ms
18,544 KB
testcase_02 AC 19 ms
18,728 KB
testcase_03 AC 18 ms
18,728 KB
testcase_04 AC 18 ms
18,768 KB
testcase_05 AC 18 ms
18,772 KB
testcase_06 AC 18 ms
18,772 KB
testcase_07 AC 18 ms
18,544 KB
testcase_08 AC 19 ms
18,860 KB
testcase_09 AC 18 ms
18,664 KB
testcase_10 AC 18 ms
18,668 KB
testcase_11 AC 20 ms
18,740 KB
testcase_12 AC 18 ms
18,572 KB
testcase_13 AC 18 ms
18,776 KB
testcase_14 AC 18 ms
18,688 KB
testcase_15 AC 18 ms
18,788 KB
testcase_16 AC 18 ms
18,800 KB
testcase_17 AC 19 ms
18,828 KB
testcase_18 AC 18 ms
18,608 KB
testcase_19 AC 18 ms
18,652 KB
testcase_20 AC 19 ms
18,760 KB
testcase_21 AC 17 ms
18,544 KB
testcase_22 AC 18 ms
18,652 KB
testcase_23 AC 19 ms
18,820 KB
testcase_24 AC 18 ms
18,568 KB
testcase_25 AC 18 ms
18,752 KB
testcase_26 AC 18 ms
18,716 KB
testcase_27 AC 18 ms
18,552 KB
testcase_28 AC 19 ms
18,360 KB
testcase_29 AC 20 ms
18,784 KB
testcase_30 AC 18 ms
18,796 KB
testcase_31 AC 19 ms
18,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll mod = 1e9 + 7;

template <ll MOD>
class Combination {
private:
    ll N;
    V<ll> factv, ifactv;

public:
    Combination<MOD>(ll N) : N(N), factv(N + 1, 1), ifactv(N + 1) {
        for(ll i = 1; i <= N; i++) factv[i] = factv[i - 1] * i % MOD;
        ifactv.back() = inv(factv.back());
        for(ll i = N - 1; 0 <= i; i--) ifactv[i] = (i + 1) * ifactv[i + 1] % MOD;
    }

    ll fact(ll n) { return factv[n]; }

    ll ifact(ll n) { return ifactv[n]; }

    ll pow(ll a, ll b) { return b ? (b & 1 ? a : 1) * pow(a * a % MOD, b / 2) % MOD : 1; }

    ll inv(ll a) { return pow(a, MOD - 2); }

    ll comb(ll n, ll k) { return factv[n] * ifactv[n - k] % MOD * ifactv[k] % MOD; }
};

Combination<mod> C(1e6 + 10);

int main() {
    ll N;
    cin >> N;
    ll dstnct = (N - 2) % mod * ((N - 3) % mod) % mod * C.ifact(2) % mod;
    ll same3 = (N - 1) % 3 == 0;
    ll same2 = (N - 2) / 2 % mod;
    (same2 += mod - same3) %= mod;
    DEBUG(make_tuple(dstnct, same2, same3));
    dstnct = (dstnct + 2 * mod - 3 * same2 % mod - same3) % mod;
    DEBUG(dstnct);
    (dstnct *= C.ifact(3)) %= mod;
    cout << (dstnct + same2 + same3) % mod << endl;
    return 0;
}
0