結果

問題 No.1111 コード進行
ユーザー soto800soto800
提出日時 2020-07-10 21:47:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 3,597 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 172,996 KB
実行使用メモリ 432,896 KB
最終ジャッジ日時 2024-04-19 16:42:15
合計ジャッジ時間 5,172 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,504 KB
testcase_08 AC 8 ms
7,168 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 7 ms
7,808 KB
testcase_16 AC 5 ms
6,400 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 5 ms
6,272 KB
testcase_23 AC 5 ms
6,144 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 9 ms
8,576 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 7 ms
7,168 KB
testcase_29 AC 23 ms
21,120 KB
testcase_30 AC 18 ms
13,824 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 38 ms
23,680 KB
testcase_33 AC 22 ms
13,952 KB
testcase_34 AC 6 ms
6,784 KB
testcase_35 AC 11 ms
10,368 KB
testcase_36 AC 170 ms
151,424 KB
testcase_37 AC 160 ms
141,184 KB
testcase_38 AC 83 ms
66,944 KB
testcase_39 AC 44 ms
30,336 KB
testcase_40 AC 126 ms
108,928 KB
testcase_41 AC 33 ms
29,568 KB
testcase_42 AC 165 ms
143,616 KB
testcase_43 AC 93 ms
75,136 KB
testcase_44 AC 48 ms
42,752 KB
testcase_45 AC 71 ms
62,976 KB
testcase_46 AC 74 ms
32,768 KB
testcase_47 AC 74 ms
32,768 KB
testcase_48 AC 530 ms
432,896 KB
testcase_49 AC 484 ms
432,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += 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 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>;

vector<pair<lli,lli>> G[310];

//dp[i][j][k]: i回やって前がjで複雑度がkになる個数
mint dp[310][310][610];

int main(){

	lli n,m,K;
	cin>>n>>m>>K;

	set<lli> s;

	REP(i,0,m){
		lli p,q,c;
		cin>>p>>q>>c;
		p--,q--;
		G[p].push_back({q,c});
		s.insert(p);
		s.insert(q);
	}
	for(auto j:s){
		dp[0][j][0] = 1;
	}

	REP(i,0,n-1){
		for(auto j:s){
			REP(k,0,305){
				REP(l,0,G[j].size()){
					lli to = G[j][l].first;
					lli cost = G[j][l].second;
					dp[i+1][to][k+cost] += dp[i][j][k];
					LOG4(dp[i+1][to][k+cost] ,dp[i][j][k],to,cost);
				}
			}
		}
	}

	mint ans = 0;
	for(auto j:s){
		ans += dp[n-1][j][K];
	}
	cout<<ans<<endl;


    return 0;
}
0