結果

問題 No.1111 コード進行
ユーザー furafura
提出日時 2020-07-10 21:38:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,807 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 200,816 KB
実行使用メモリ 109,568 KB
最終ジャッジ日時 2024-04-19 16:16:58
合計ジャッジ時間 5,791 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
109,312 KB
testcase_01 AC 31 ms
109,440 KB
testcase_02 AC 30 ms
109,440 KB
testcase_03 AC 33 ms
109,520 KB
testcase_04 AC 32 ms
109,440 KB
testcase_05 AC 31 ms
109,452 KB
testcase_06 AC 32 ms
109,440 KB
testcase_07 AC 32 ms
109,568 KB
testcase_08 AC 33 ms
109,500 KB
testcase_09 AC 32 ms
109,412 KB
testcase_10 AC 33 ms
109,412 KB
testcase_11 AC 34 ms
109,388 KB
testcase_12 AC 34 ms
109,568 KB
testcase_13 AC 33 ms
109,444 KB
testcase_14 AC 32 ms
109,568 KB
testcase_15 AC 33 ms
109,440 KB
testcase_16 AC 33 ms
109,404 KB
testcase_17 AC 32 ms
109,568 KB
testcase_18 AC 33 ms
109,376 KB
testcase_19 AC 32 ms
109,568 KB
testcase_20 AC 34 ms
109,440 KB
testcase_21 AC 33 ms
109,568 KB
testcase_22 AC 33 ms
109,508 KB
testcase_23 AC 33 ms
109,428 KB
testcase_24 AC 32 ms
109,408 KB
testcase_25 AC 32 ms
109,444 KB
testcase_26 AC 32 ms
109,568 KB
testcase_27 AC 31 ms
109,528 KB
testcase_28 AC 32 ms
109,312 KB
testcase_29 AC 34 ms
109,568 KB
testcase_30 AC 33 ms
109,400 KB
testcase_31 AC 33 ms
109,568 KB
testcase_32 AC 48 ms
109,440 KB
testcase_33 AC 38 ms
109,440 KB
testcase_34 AC 32 ms
109,440 KB
testcase_35 AC 33 ms
109,568 KB
testcase_36 AC 48 ms
109,568 KB
testcase_37 AC 52 ms
109,568 KB
testcase_38 AC 45 ms
109,440 KB
testcase_39 AC 42 ms
109,440 KB
testcase_40 AC 48 ms
109,568 KB
testcase_41 AC 36 ms
109,416 KB
testcase_42 AC 50 ms
109,568 KB
testcase_43 AC 44 ms
109,440 KB
testcase_44 AC 37 ms
109,568 KB
testcase_45 AC 39 ms
109,444 KB
testcase_46 AC 59 ms
109,440 KB
testcase_47 AC 60 ms
109,312 KB
testcase_48 AC 63 ms
109,420 KB
testcase_49 AC 64 ms
109,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int main(){
	int n,m,k; scanf("%d%d%d",&n,&m,&k);
	vector<pair<int,int>> p[300];
	rep(i,m){
		int a,b,c; scanf("%d%d%d",&a,&b,&c); a--; b--;
		p[a].emplace_back(b,c);
	}

	static mint dp[300][300][301];
	rep(j,300) dp[0][j][0]=1;
	rep(i,n-1) rep(j,300) {
		for(auto [to,cost]:p[j]){
			rep(k,301-cost) dp[i+1][to][k+cost]+=dp[i][j][k];
		}
	}

	mint ans=0;
	rep(j,300) ans+=dp[n-1][j][k];
	cout<<ans<<'\n';

	return 0;
}
0