結果

問題 No.1111 コード進行
ユーザー totori_nyaatotori_nyaa
提出日時 2020-07-10 21:55:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 2,870 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 200,196 KB
実行使用メモリ 147,840 KB
最終ジャッジ日時 2024-04-19 16:59:47
合計ジャッジ時間 5,887 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
147,584 KB
testcase_01 AC 50 ms
147,756 KB
testcase_02 AC 50 ms
147,712 KB
testcase_03 AC 50 ms
147,712 KB
testcase_04 AC 49 ms
147,712 KB
testcase_05 AC 49 ms
147,712 KB
testcase_06 AC 50 ms
147,584 KB
testcase_07 AC 49 ms
147,648 KB
testcase_08 AC 51 ms
147,712 KB
testcase_09 AC 49 ms
147,704 KB
testcase_10 AC 50 ms
147,584 KB
testcase_11 AC 50 ms
147,584 KB
testcase_12 AC 49 ms
147,584 KB
testcase_13 AC 50 ms
147,712 KB
testcase_14 AC 50 ms
147,584 KB
testcase_15 AC 49 ms
147,616 KB
testcase_16 AC 50 ms
147,712 KB
testcase_17 AC 50 ms
147,700 KB
testcase_18 AC 50 ms
147,712 KB
testcase_19 AC 49 ms
147,584 KB
testcase_20 AC 49 ms
147,628 KB
testcase_21 AC 50 ms
147,712 KB
testcase_22 AC 51 ms
147,584 KB
testcase_23 AC 54 ms
147,712 KB
testcase_24 AC 47 ms
147,584 KB
testcase_25 AC 48 ms
147,584 KB
testcase_26 AC 47 ms
147,712 KB
testcase_27 AC 46 ms
147,840 KB
testcase_28 AC 48 ms
147,584 KB
testcase_29 AC 48 ms
147,712 KB
testcase_30 AC 50 ms
147,584 KB
testcase_31 AC 47 ms
147,712 KB
testcase_32 AC 52 ms
147,712 KB
testcase_33 AC 52 ms
147,584 KB
testcase_34 AC 47 ms
147,620 KB
testcase_35 AC 49 ms
147,712 KB
testcase_36 AC 63 ms
147,840 KB
testcase_37 AC 57 ms
147,712 KB
testcase_38 AC 51 ms
147,712 KB
testcase_39 AC 96 ms
147,840 KB
testcase_40 AC 51 ms
147,712 KB
testcase_41 AC 40 ms
147,840 KB
testcase_42 AC 47 ms
147,712 KB
testcase_43 AC 44 ms
147,712 KB
testcase_44 AC 40 ms
147,572 KB
testcase_45 AC 43 ms
147,692 KB
testcase_46 AC 38 ms
147,712 KB
testcase_47 AC 61 ms
147,584 KB
testcase_48 AC 41 ms
147,712 KB
testcase_49 AC 39 ms
147,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};


template< int mod = 1000000007 >
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; }
};

const int mod = 1000000007;
// const int mod = 998244353;
using mint = ModInt< mod >;
vector<vector<array<int,2>>> v(1000);
mint dp[333][333][333];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        v[a].push_back({b,c});
        dp[1][a][0] = 1;
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<300;j++){
            for(auto e:v[j]){
                for(int cost=0;cost+e[1]<=k;cost++){
                    dp[i+1][e[0]][cost+e[1]] += dp[i][j][cost];
                }
            }
        }
    }
    mint ans = 0;
    for(int i=0;i<300;i++)ans += dp[n][i][k];
    cout << ans << endl;
}
0