結果

問題 No.1111 コード進行
ユーザー rokahikou1rokahikou1
提出日時 2020-07-10 22:26:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 3,697 bytes
コンパイル時間 1,355 ms
コンパイル使用メモリ 105,268 KB
実行使用メモリ 240,640 KB
最終ジャッジ日時 2024-04-19 17:37:02
合計ジャッジ時間 12,118 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 179 ms
240,512 KB
testcase_01 AC 177 ms
240,384 KB
testcase_02 AC 177 ms
240,512 KB
testcase_03 AC 182 ms
240,640 KB
testcase_04 AC 187 ms
240,512 KB
testcase_05 AC 179 ms
240,512 KB
testcase_06 AC 176 ms
240,640 KB
testcase_07 AC 177 ms
240,512 KB
testcase_08 AC 178 ms
240,512 KB
testcase_09 AC 177 ms
240,640 KB
testcase_10 AC 179 ms
240,512 KB
testcase_11 AC 176 ms
240,384 KB
testcase_12 AC 179 ms
240,512 KB
testcase_13 AC 182 ms
240,640 KB
testcase_14 AC 184 ms
240,512 KB
testcase_15 AC 177 ms
240,512 KB
testcase_16 AC 179 ms
240,512 KB
testcase_17 AC 176 ms
240,640 KB
testcase_18 AC 181 ms
240,512 KB
testcase_19 AC 177 ms
240,512 KB
testcase_20 AC 176 ms
240,640 KB
testcase_21 AC 178 ms
240,512 KB
testcase_22 AC 179 ms
240,640 KB
testcase_23 AC 179 ms
240,512 KB
testcase_24 AC 179 ms
240,640 KB
testcase_25 AC 180 ms
240,512 KB
testcase_26 AC 188 ms
240,384 KB
testcase_27 AC 175 ms
240,512 KB
testcase_28 AC 196 ms
240,512 KB
testcase_29 AC 185 ms
240,512 KB
testcase_30 AC 191 ms
240,512 KB
testcase_31 AC 182 ms
240,512 KB
testcase_32 AC 195 ms
240,640 KB
testcase_33 AC 199 ms
240,512 KB
testcase_34 AC 189 ms
240,512 KB
testcase_35 AC 191 ms
240,512 KB
testcase_36 AC 221 ms
240,512 KB
testcase_37 AC 198 ms
240,512 KB
testcase_38 AC 200 ms
240,512 KB
testcase_39 AC 211 ms
240,640 KB
testcase_40 AC 216 ms
240,640 KB
testcase_41 AC 200 ms
240,512 KB
testcase_42 AC 212 ms
240,512 KB
testcase_43 AC 197 ms
240,512 KB
testcase_44 AC 184 ms
240,512 KB
testcase_45 AC 203 ms
240,512 KB
testcase_46 AC 182 ms
240,640 KB
testcase_47 AC 269 ms
240,512 KB
testcase_48 AC 179 ms
240,384 KB
testcase_49 AC 178 ms
240,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template <uint_fast64_t MOD> class ModInt {
    using u64 = uint_fast64_t;

  public:
    u64 val;

    ModInt(const u64 x = 0) : val(x % MOD) {}
    constexpr u64 &value() { return val; }
    constexpr ModInt operator-() { return val ? MOD - val : 0; }
    constexpr ModInt operator+(const ModInt &rhs) const {
        return ModInt(*this) += rhs;
    }
    constexpr ModInt operator-(const ModInt &rhs) const {
        return ModInt(*this) -= rhs;
    }
    constexpr ModInt operator*(const ModInt &rhs) const {
        return ModInt(*this) *= rhs;
    }
    constexpr ModInt operator/(const ModInt &rhs) const {
        return ModInt(*this) /= rhs;
    }
    constexpr ModInt &operator+=(const ModInt &rhs) {
        val += rhs.val;
        if(val >= MOD) {
            val -= MOD;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &rhs) {
        if(val < rhs.val) {
            val += MOD;
        }
        val -= rhs.val;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &rhs) {
        val = val * rhs.val % MOD;
        return *this;
    }

    constexpr ModInt &operator/=(const ModInt &rhs) {
        *this *= rhs.inv();
        return *this;
    }

    constexpr bool operator==(const ModInt &rhs) { return this->a == rhs.a; }
    constexpr bool operator!=(const ModInt &rhs) { return this->a != rhs.a; }
    friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) {
        return os << x.val;
    }
    friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) {
        return is >> x.val;
    }

    constexpr ModInt inv() const {
        u64 x = val, y = MOD, u = 1, v = 0, t = 0;
        while(y > 0) {
            t = x / y;
            x -= t * y;
            swap(x, y);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    constexpr ModInt pow(int e) const {
        u64 x = 1, p = val;
        while(e > 0) {
            if(e % 2 == 0) {
                p = (p * p) % MOD;
                e /= 2;
            } else {
                x = (x * p) % MOD;
                e--;
            }
        }
        return ModInt(x);
    }
};

using mint = ModInt<MOD>;

int main() {
    vector<vector<vector<mint>>> dp(
        310, vector<vector<mint>>(310, vector<mint>(310)));
    // dp[i][j][k]:=i個目まで見て、今見てるのがjで、複雑度がkとなる通り数

    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<pii>> G(300, vector<pii>());
    rep(i, M) {
        int p, q, c;
        cin >> p >> q >> c;
        p--, q--;
        G[p].pb(MP(q, c));
    }

    for(int i = 0; i < 300; i++) {
        dp[1][i][0] = 1;
    }

    for(int i = 1; i < N; i++) {
        for(int j = 0; j < 300; j++) {
            for(int k = 0; k <= K; k++) {
                for(auto p : G[j]) {
                    if(k + p.second <= K)
                        dp[i + 1][p.first][k + p.second] += dp[i][j][k];
                }
            }
        }
    }
    mint res = 0;
    rep(i, 300) { res += dp[N][i][K]; }
    cout << res << endl;
    return 0;
}
0