結果

問題 No.906 Y字グラフ
ユーザー batsumarubatsumaru
提出日時 2019-10-11 23:24:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,407 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 167,876 KB
実行使用メモリ 8,264 KB
最終ジャッジ日時 2024-05-04 03:20:12
合計ジャッジ時間 2,844 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,136 KB
testcase_01 AC 6 ms
8,136 KB
testcase_02 AC 5 ms
8,136 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 7 ms
8,260 KB
testcase_08 AC 6 ms
8,132 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 6 ms
8,012 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 7 ms
8,008 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 7 ms
8,136 KB
testcase_22 AC 6 ms
8,140 KB
testcase_23 WA -
testcase_24 AC 6 ms
8,140 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 6 ms
8,140 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 5 ms
8,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

/* 二項係数 C(n,k) mod p を計算 */
const int MOD = 1000000007;
const int MAX = 201000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  ll n;
  cin >> n;
  COMinit();
  ll a = ((n - 4) % 3 == 0);                            // 3つ同じ
  ll b = ((!a) + ((n - 4)/2) % MOD * 3 % MOD)%MOD;          // 2つ同じ
  ll c = (n - 2) % MOD * ((n - 3) % MOD) % MOD * inv[2] % MOD;  //全体
  // DUMP(a);
  // DUMP(b);
  // DUMP(c);
  ll ans =
      ((c + (MOD - b) % MOD) % MOD + (MOD - a) % MOD) % MOD * finv[3] % MOD +
      (b * inv[3]) % MOD + a;
  ans %= MOD;
  cout << ans << endl;
}
0