結果

問題 No.1111 コード進行
ユーザー mikianaaamikianaaa
提出日時 2020-09-28 20:50:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 3,046 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 168,224 KB
実行使用メモリ 222,712 KB
最終ジャッジ日時 2023-09-15 11:42:34
合計ジャッジ時間 5,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,736 KB
testcase_07 AC 3 ms
4,696 KB
testcase_08 AC 3 ms
4,616 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,404 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,832 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 5 ms
5,464 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 4 ms
5,060 KB
testcase_23 AC 3 ms
4,616 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 7 ms
6,780 KB
testcase_26 AC 4 ms
4,780 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 6 ms
6,360 KB
testcase_29 AC 17 ms
16,584 KB
testcase_30 AC 16 ms
12,472 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 25 ms
17,780 KB
testcase_33 AC 20 ms
11,788 KB
testcase_34 AC 4 ms
5,912 KB
testcase_35 AC 9 ms
9,004 KB
testcase_36 AC 130 ms
108,132 KB
testcase_37 AC 96 ms
89,500 KB
testcase_38 AC 49 ms
45,056 KB
testcase_39 AC 40 ms
26,100 KB
testcase_40 AC 101 ms
85,564 KB
testcase_41 AC 27 ms
25,612 KB
testcase_42 AC 106 ms
96,320 KB
testcase_43 AC 63 ms
54,524 KB
testcase_44 AC 32 ms
30,972 KB
testcase_45 AC 53 ms
49,352 KB
testcase_46 AC 19 ms
18,360 KB
testcase_47 AC 74 ms
19,232 KB
testcase_48 AC 240 ms
222,712 KB
testcase_49 AC 169 ms
164,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

template <int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0)
            v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+(const Fp &r) const noexcept {
        return Fp(*this) += r;
    }
    constexpr Fp operator-(const Fp &r) const noexcept {
        return Fp(*this) -= r;
    }
    constexpr Fp operator*(const Fp &r) const noexcept {
        return Fp(*this) *= r;
    }
    constexpr Fp operator/(const Fp &r) const noexcept {
        return Fp(*this) /= r;
    }
    constexpr Fp &operator+=(const Fp &r) noexcept {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp &operator-=(const Fp &r) noexcept {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator*=(const Fp &r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp &operator/=(const Fp &r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp &r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp &r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os,
                                         const Fp<MOD> &x) noexcept {
        return os << x.val;
    }
    friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;

// i番目まででjにおり、複雑度k
mint dp[310][310][310] = {0};

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> P(M), Q(M), C(M);
    rep(i, M) {
        cin >> P[i] >> Q[i] >> C[i];
        dp[0][P[i]][0] = 1;
    }

    vector<ll> prev(K + 10, -1);
    rep(i, N) {
        rep(j, M) {
            rep(k, K + 1) {
                if (k + C[j] <= K) {
                    dp[i + 1][Q[j]][k + C[j]] += dp[i][P[j]][k];
                }
            }
        }
    }

    mint ans = 0;
    rep(j, 310) { ans += dp[N - 1][j][K]; }

    cout << ans << endl;
}
0