結果

問題 No.1111 コード進行
ユーザー renjyaku_intrenjyaku_int
提出日時 2020-09-05 17:48:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 2,481 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 209,588 KB
実行使用メモリ 218,132 KB
最終ジャッジ日時 2023-08-19 10:57:09
合計ジャッジ時間 7,887 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
6,004 KB
testcase_06 AC 6 ms
7,852 KB
testcase_07 AC 6 ms
7,324 KB
testcase_08 AC 3 ms
4,496 KB
testcase_09 AC 4 ms
6,212 KB
testcase_10 AC 8 ms
9,736 KB
testcase_11 AC 4 ms
4,680 KB
testcase_12 AC 6 ms
7,848 KB
testcase_13 AC 5 ms
6,536 KB
testcase_14 AC 9 ms
10,200 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 7 ms
8,256 KB
testcase_17 AC 8 ms
9,912 KB
testcase_18 AC 3 ms
4,564 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 4 ms
5,448 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 10 ms
12,076 KB
testcase_23 AC 5 ms
6,216 KB
testcase_24 AC 6 ms
7,060 KB
testcase_25 AC 10 ms
11,724 KB
testcase_26 AC 7 ms
7,564 KB
testcase_27 AC 3 ms
4,432 KB
testcase_28 AC 97 ms
110,712 KB
testcase_29 AC 43 ms
48,080 KB
testcase_30 AC 73 ms
74,052 KB
testcase_31 AC 12 ms
15,284 KB
testcase_32 AC 78 ms
67,248 KB
testcase_33 AC 60 ms
44,548 KB
testcase_34 AC 71 ms
80,604 KB
testcase_35 AC 92 ms
103,104 KB
testcase_36 AC 95 ms
109,136 KB
testcase_37 AC 29 ms
29,608 KB
testcase_38 AC 30 ms
22,804 KB
testcase_39 AC 100 ms
73,324 KB
testcase_40 AC 117 ms
100,776 KB
testcase_41 AC 107 ms
123,052 KB
testcase_42 AC 49 ms
51,624 KB
testcase_43 AC 61 ms
45,344 KB
testcase_44 AC 24 ms
26,040 KB
testcase_45 AC 67 ms
75,600 KB
testcase_46 AC 10 ms
8,340 KB
testcase_47 AC 196 ms
218,132 KB
testcase_48 AC 9 ms
8,360 KB
testcase_49 AC 10 ms
8,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << 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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<pair<ll, ll>>> v(300);
    rep(i, m)
    {
        ll p, q, c;
        cin >> p >> q >> c;
        p--;
        q--;
        v[p].push_back(make_pair(q, c));
    }
    vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(300, vector<ll>(k + 1, -1)));
    rep(i, 300)
    {
        dp[0][i][0] = 1;
    }
    rep(i, n-1)
    {
        rep(j, 300)
        {
            rep(l, k + 1)
            {
                if (dp[i][j][l] == -1)
                    continue;
                rep(h, v[j].size())
                {
                    if (l + v[j][h].second > k)
                        continue;
                    if (dp[i + 1][v[j][h].first][l + v[j][h].second] == -1)
                    {
                        dp[i + 1][v[j][h].first][l + v[j][h].second] = 0;
                    }
                    dp[i + 1][v[j][h].first][l + v[j][h].second] += dp[i][j][l];
                    dp[i + 1][v[j][h].first][l + v[j][h].second] %= MOD;
                }
            }
        }
    }
    ll ans = 0;
    rep(i, 300)
    {
        if (dp[n-1][i][k] != -1)
        {
            ans += dp[n-1][i][k];
            ans %= MOD;
        }
    }
    cout << ans << "\n";
}
0