結果

問題 No.314 ケンケンパ
ユーザー heabiheabi
提出日時 2020-11-22 09:55:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 1,000 ms
コード長 2,722 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 167,456 KB
実行使用メモリ 26,980 KB
最終ジャッジ日時 2023-09-30 22:33:25
合計ジャッジ時間 3,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
26,980 KB
testcase_01 AC 32 ms
26,808 KB
testcase_02 AC 33 ms
26,864 KB
testcase_03 AC 32 ms
26,820 KB
testcase_04 AC 33 ms
26,840 KB
testcase_05 AC 32 ms
26,820 KB
testcase_06 AC 34 ms
26,796 KB
testcase_07 AC 31 ms
26,860 KB
testcase_08 AC 32 ms
26,908 KB
testcase_09 AC 32 ms
26,844 KB
testcase_10 AC 31 ms
26,816 KB
testcase_11 AC 31 ms
26,808 KB
testcase_12 AC 32 ms
26,856 KB
testcase_13 AC 33 ms
26,868 KB
testcase_14 AC 33 ms
26,872 KB
testcase_15 AC 33 ms
26,812 KB
testcase_16 AC 32 ms
26,812 KB
testcase_17 AC 32 ms
26,824 KB
testcase_18 AC 35 ms
26,816 KB
testcase_19 AC 37 ms
26,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
// constexpr ll mod = 998244353;
// constexpr ll mod = 67280421310721;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void pt_vvll(vvll v) {
    ll vs = v.size(), vs0 = v[0].size();
    rep(i, vs) {
        rep(j, vs0) {
            cout << v[i][j];

            if (j != vs0 - 1)
                cout << " ";
            else
                cout << "\n";
        }
    }
}
void pt_vll(vll v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];
        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

#define MAX 1000100
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}
// 二項係数計算
ll combi(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// mainに   COMinit();   を入れる

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();

    ll N;
    cin >> N;
    ll ans = 0;
    //末尾パ
    for (ll i = 0; 3 * i <= N; i++) {
        ll rem = N - 3 * i;
        if (rem % 2 == 1) {
            continue;
        }
        ans += combi(i + rem / 2, min(i, rem / 2));
        ans %= mod;
    }
    //末尾ケン
    for (ll i = 0; 3 * i <= N - 1; i++) {
        ll rem = N - 1 - 3 * i;
        if (rem % 2 == 1) {
            continue;
        }
        ans += combi(i + rem / 2, min(i, rem / 2));
        ans %= mod;
    }

    //末尾ケンケン
    for (ll i = 0; 3 * i <= N - 2; i++) {
        ll rem = N - 2 - 3 * i;
        if (rem % 2 == 1) {
            continue;
        }
        ans += combi(i + rem / 2, min(i, rem / 2));
        ans %= mod;
    }

    cout << ans << "\n";
    return 0;
}
0