結果

問題 No.1111 コード進行
ユーザー furafura
提出日時 2020-07-10 21:38:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,807 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 203,832 KB
実行使用メモリ 109,536 KB
最終ジャッジ日時 2023-08-01 17:01:16
合計ジャッジ時間 5,617 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
109,200 KB
testcase_01 AC 31 ms
109,380 KB
testcase_02 AC 30 ms
109,204 KB
testcase_03 AC 30 ms
109,284 KB
testcase_04 AC 29 ms
109,332 KB
testcase_05 AC 30 ms
109,316 KB
testcase_06 AC 30 ms
109,320 KB
testcase_07 AC 30 ms
109,260 KB
testcase_08 AC 31 ms
109,500 KB
testcase_09 AC 30 ms
109,368 KB
testcase_10 AC 30 ms
109,212 KB
testcase_11 AC 31 ms
109,284 KB
testcase_12 AC 30 ms
109,260 KB
testcase_13 AC 30 ms
109,400 KB
testcase_14 AC 31 ms
109,376 KB
testcase_15 AC 30 ms
109,228 KB
testcase_16 AC 31 ms
109,312 KB
testcase_17 AC 30 ms
109,212 KB
testcase_18 AC 30 ms
109,312 KB
testcase_19 AC 30 ms
109,324 KB
testcase_20 AC 30 ms
109,208 KB
testcase_21 AC 30 ms
109,304 KB
testcase_22 AC 30 ms
109,376 KB
testcase_23 AC 30 ms
109,216 KB
testcase_24 AC 30 ms
109,300 KB
testcase_25 AC 31 ms
109,336 KB
testcase_26 AC 31 ms
109,336 KB
testcase_27 AC 30 ms
109,372 KB
testcase_28 AC 30 ms
109,260 KB
testcase_29 AC 31 ms
109,312 KB
testcase_30 AC 33 ms
109,256 KB
testcase_31 AC 30 ms
109,372 KB
testcase_32 AC 40 ms
109,304 KB
testcase_33 AC 36 ms
109,212 KB
testcase_34 AC 31 ms
109,296 KB
testcase_35 AC 32 ms
109,536 KB
testcase_36 AC 47 ms
109,408 KB
testcase_37 AC 47 ms
109,260 KB
testcase_38 AC 43 ms
109,380 KB
testcase_39 AC 39 ms
109,224 KB
testcase_40 AC 44 ms
109,208 KB
testcase_41 AC 33 ms
109,220 KB
testcase_42 AC 46 ms
109,336 KB
testcase_43 AC 42 ms
109,376 KB
testcase_44 AC 34 ms
109,256 KB
testcase_45 AC 36 ms
109,304 KB
testcase_46 AC 56 ms
109,212 KB
testcase_47 AC 56 ms
109,372 KB
testcase_48 AC 57 ms
109,396 KB
testcase_49 AC 59 ms
109,320 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