結果
問題 | No.906 Y字グラフ |
ユーザー |
![]() |
提出日時 | 2019-10-11 22:01:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 2,861 bytes |
コンパイル時間 | 1,569 ms |
コンパイル使用メモリ | 171,864 KB |
実行使用メモリ | 18,956 KB |
最終ジャッジ日時 | 2024-11-25 07:27:31 |
合計ジャッジ時間 | 3,036 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
ソースコード
// #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#endiftemplate <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;}