結果

問題 No.1111 コード進行
ユーザー 👑 jupirojupiro
提出日時 2020-07-10 21:28:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 2,604 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 138,092 KB
実行使用メモリ 218,496 KB
最終ジャッジ日時 2024-04-19 15:41:57
合計ジャッジ時間 4,417 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 4 ms
6,144 KB
testcase_06 AC 6 ms
8,320 KB
testcase_07 AC 6 ms
7,424 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
6,400 KB
testcase_10 AC 7 ms
9,856 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 6 ms
8,192 KB
testcase_13 AC 4 ms
6,912 KB
testcase_14 AC 9 ms
10,496 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 6 ms
8,704 KB
testcase_17 AC 7 ms
10,240 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,888 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 9 ms
12,416 KB
testcase_23 AC 4 ms
6,528 KB
testcase_24 AC 5 ms
7,424 KB
testcase_25 AC 10 ms
11,648 KB
testcase_26 AC 6 ms
7,808 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 98 ms
111,104 KB
testcase_29 AC 45 ms
48,256 KB
testcase_30 AC 78 ms
74,368 KB
testcase_31 AC 13 ms
15,488 KB
testcase_32 AC 89 ms
67,584 KB
testcase_33 AC 71 ms
44,672 KB
testcase_34 AC 74 ms
81,024 KB
testcase_35 AC 94 ms
103,296 KB
testcase_36 AC 127 ms
109,696 KB
testcase_37 AC 35 ms
29,824 KB
testcase_38 AC 32 ms
22,784 KB
testcase_39 AC 119 ms
73,472 KB
testcase_40 AC 131 ms
100,992 KB
testcase_41 AC 117 ms
123,136 KB
testcase_42 AC 65 ms
51,968 KB
testcase_43 AC 68 ms
45,824 KB
testcase_44 AC 26 ms
26,240 KB
testcase_45 AC 76 ms
75,904 KB
testcase_46 AC 9 ms
8,704 KB
testcase_47 AC 259 ms
218,496 KB
testcase_48 AC 9 ms
8,576 KB
testcase_49 AC 9 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

ll n, m, K;
vector<pair<int, ll>> g[300];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%lld %lld %lld", &n, &m, &K);
	for (int i = 0; i < m; i++) {
		int p, q, c; scanf("%d %d %d", &p, &q, &c);
		p--; q--;
		g[p].emplace_back(q, c);
	}
	vector dp(n, vector(300, vector<mint>(K + 1)));
	for (int i = 0; i < 300; i++) dp[0][i][0] = 1;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < 300; j++) {
			for (int k = 0; k <= K; k++) {
				for (auto nxt : g[j]) {
					if (k + nxt.second > K) continue;
					dp[i + 1][nxt.first][k + nxt.second] += dp[i][j][k];
				}
			}
		}
	}
	mint res = 0;
	for (int i = 0; i < 300; i++) res += dp[n - 1][i][K];
	cout << res.x << endl;
	return 0;
}
0