結果

問題 No.1111 コード進行
ユーザー siro53siro53
提出日時 2020-07-10 22:43:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 3,756 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 200,608 KB
実行使用メモリ 120,052 KB
最終ジャッジ日時 2024-04-19 17:56:02
合計ジャッジ時間 5,367 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
119,844 KB
testcase_01 AC 30 ms
119,836 KB
testcase_02 AC 30 ms
119,924 KB
testcase_03 AC 30 ms
119,724 KB
testcase_04 AC 30 ms
119,704 KB
testcase_05 AC 30 ms
120,012 KB
testcase_06 AC 31 ms
119,816 KB
testcase_07 AC 32 ms
119,900 KB
testcase_08 AC 32 ms
119,884 KB
testcase_09 AC 31 ms
119,952 KB
testcase_10 AC 32 ms
119,692 KB
testcase_11 AC 31 ms
119,868 KB
testcase_12 AC 32 ms
119,904 KB
testcase_13 AC 30 ms
119,972 KB
testcase_14 AC 32 ms
119,848 KB
testcase_15 AC 32 ms
119,848 KB
testcase_16 AC 33 ms
119,964 KB
testcase_17 AC 31 ms
119,852 KB
testcase_18 AC 31 ms
120,000 KB
testcase_19 AC 30 ms
119,860 KB
testcase_20 AC 30 ms
120,052 KB
testcase_21 AC 32 ms
119,880 KB
testcase_22 AC 33 ms
119,932 KB
testcase_23 AC 32 ms
119,824 KB
testcase_24 AC 32 ms
119,772 KB
testcase_25 AC 34 ms
119,952 KB
testcase_26 AC 34 ms
119,932 KB
testcase_27 AC 30 ms
119,816 KB
testcase_28 AC 48 ms
119,940 KB
testcase_29 AC 48 ms
119,900 KB
testcase_30 AC 44 ms
119,688 KB
testcase_31 AC 32 ms
119,760 KB
testcase_32 AC 67 ms
119,828 KB
testcase_33 AC 46 ms
119,840 KB
testcase_34 AC 44 ms
119,740 KB
testcase_35 AC 57 ms
119,844 KB
testcase_36 AC 67 ms
119,828 KB
testcase_37 AC 67 ms
120,036 KB
testcase_38 AC 58 ms
120,028 KB
testcase_39 AC 54 ms
119,848 KB
testcase_40 AC 66 ms
120,040 KB
testcase_41 AC 52 ms
119,964 KB
testcase_42 AC 67 ms
119,916 KB
testcase_43 AC 56 ms
119,988 KB
testcase_44 AC 46 ms
119,876 KB
testcase_45 AC 53 ms
119,796 KB
testcase_46 AC 100 ms
119,932 KB
testcase_47 AC 100 ms
119,852 KB
testcase_48 AC 95 ms
119,964 KB
testcase_49 AC 96 ms
119,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

template <int mod> struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt<MOD>;

mint dp[310][310][310];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<pair<int, int>>> g(300);
    for(int i = 0; i < M; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        p--;
        q--;
        g[p].emplace_back(q, c);
    }
    for(int j = 0; j < 300; j++) {
        dp[0][j][0] = 1;
    }
    for(int i = 0; i < N - 1; i++) {
        for(int j = 0; j < 300; j++) {
            for(int k = 0; k <= 300; k++) {
                for(const auto &nxt : g[j]) {
                    if(k + nxt.second <= 300) {
                        dp[i + 1][nxt.first][k + nxt.second] += dp[i][j][k];
                    }
                }
            }
        }
    }
    mint ans = 0;
    for(int j = 0; j < 300; j++) {
        // debug(j, dp[N - 1][j][K]);
        ans += dp[N - 1][j][K];
    }
    cout << ans << endl;
}
0