結果

問題 No.1111 コード進行
ユーザー fastmathfastmath
提出日時 2020-07-10 21:49:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,627 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 167,156 KB
実行使用メモリ 112,844 KB
最終ジャッジ日時 2023-08-01 17:33:00
合計ジャッジ時間 5,353 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,808 KB
testcase_01 AC 3 ms
4,440 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,468 KB
testcase_06 AC 5 ms
6,432 KB
testcase_07 AC 8 ms
8,356 KB
testcase_08 AC 7 ms
7,852 KB
testcase_09 AC 4 ms
5,136 KB
testcase_10 AC 9 ms
9,944 KB
testcase_11 AC 6 ms
7,212 KB
testcase_12 AC 6 ms
6,528 KB
testcase_13 AC 5 ms
6,000 KB
testcase_14 AC 8 ms
7,872 KB
testcase_15 AC 8 ms
9,324 KB
testcase_16 AC 6 ms
6,828 KB
testcase_17 AC 9 ms
9,972 KB
testcase_18 AC 6 ms
7,736 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
5,156 KB
testcase_21 AC 6 ms
8,536 KB
testcase_22 AC 9 ms
9,736 KB
testcase_23 AC 6 ms
7,556 KB
testcase_24 AC 6 ms
6,648 KB
testcase_25 AC 10 ms
10,128 KB
testcase_26 AC 9 ms
8,964 KB
testcase_27 AC 3 ms
4,616 KB
testcase_28 AC 89 ms
68,416 KB
testcase_29 AC 75 ms
65,532 KB
testcase_30 AC 63 ms
46,024 KB
testcase_31 AC 12 ms
12,156 KB
testcase_32 AC 108 ms
85,160 KB
testcase_33 AC 48 ms
30,684 KB
testcase_34 AC 71 ms
57,916 KB
testcase_35 AC 118 ms
99,268 KB
testcase_36 AC 90 ms
69,664 KB
testcase_37 AC 71 ms
64,360 KB
testcase_38 AC 56 ms
47,136 KB
testcase_39 AC 74 ms
44,032 KB
testcase_40 AC 107 ms
73,296 KB
testcase_41 AC 104 ms
80,188 KB
testcase_42 AC 80 ms
68,808 KB
testcase_43 AC 62 ms
45,468 KB
testcase_44 AC 43 ms
40,580 KB
testcase_45 AC 82 ms
67,436 KB
testcase_46 AC 113 ms
112,152 KB
testcase_47 AC 154 ms
112,604 KB
testcase_48 AC 114 ms
112,844 KB
testcase_49 AC 113 ms
112,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 307, MOD = 1000 * 1000 * 1000 + 7;
int dp[N][N][N];
int w[N][N];

vector <int> g[N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        w[u][v] = c;
        g[u].app(v);
    }   

    auto add = [&](int &a, int b) {
        a += b;
        if (a >= MOD)
            a -= MOD;
    };   

    for (int i = 1; i <= 300; ++i)
        dp[1][i][0] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int u = 1; u <= 300; ++u) {
            for (int sum = 0; sum <= k; ++sum) {

                int &x = dp[i][u][sum];
                x %= MOD;
                if (x == 0)
                    continue;

                //cout << i << ' ' << u << ' ' << sum << " : " << dp[i][u][sum] << endl;

                for (int v : g[u]) {
                    if (sum + w[u][v] <= k) {
                        add(dp[i+1][v][sum+w[u][v]], x);
                    }            
                }   
            }
        }   
    }
    
    int ans = 0;
    for (int i = 1; i <= 300; ++i)
        add(ans, dp[n][i][k]);
    cout << ans << endl;
}
0