結果

問題 No.906 Y字グラフ
ユーザー Y17Y17
提出日時 2019-10-11 23:19:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 1,348 ms
コンパイル使用メモリ 158,528 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-04 03:14:07
合計ジャッジ時間 2,038 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

#define int long long

int pow_mod(int n, int m){
    int ans = 1;
    while(m != 0){
        if(m & 1) ans = ans * n % MOD;
        n = n * n % MOD;
        m >>= 1;
    }
    return ans;
}

int combi(int n, int r){
    int a1, a2;
    n %= MOD;
    a1 = a2 = 1;
    for(int i = 0;i < r;i++){
        a1 = (a1 * (n-i)) % MOD;
        a2 = (a2 * (r-i)) % MOD;
    }

    return a1 * pow_mod(a2, MOD-2) % MOD;
}

signed main(){
    int n;
    cin >> n;
    int ans = combi(n-4+2, 2);

    int a2, a3;

    if(n > 4){
        a3 = (n-4) % 3 == 0 ? 1 : 0;

        a2 = ((n-4) / 2) % MOD * 3;
        a2 %= MOD;

        //if((n-4) % 6 == 0) a2--;

        ans -= a2 + a3;
        if(ans < 0) ans = MOD-ans;

        ans *= pow_mod(3*2, MOD-2);
        ans %= MOD;

        ans += ((n-4) / 2) % MOD;
        ans += a3;

        ans %= MOD;

        cout << ans << endl;

    }else{
        cout << 1 << endl;
    }
    return 0;
}
0