結果

問題 No.1111 コード進行
ユーザー fastmathfastmath
提出日時 2020-07-10 21:49:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,627 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 167,388 KB
実行使用メモリ 112,984 KB
最終ジャッジ日時 2024-04-19 16:46:03
合計ジャッジ時間 4,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 5 ms
8,360 KB
testcase_08 AC 5 ms
8,192 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 8 ms
10,220 KB
testcase_11 AC 5 ms
7,296 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 7 ms
8,064 KB
testcase_15 AC 6 ms
9,592 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 9 ms
10,112 KB
testcase_18 AC 5 ms
7,936 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 5 ms
8,668 KB
testcase_22 AC 9 ms
9,856 KB
testcase_23 AC 5 ms
8,160 KB
testcase_24 AC 5 ms
6,940 KB
testcase_25 AC 8 ms
10,112 KB
testcase_26 AC 8 ms
9,216 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 81 ms
68,536 KB
testcase_29 AC 68 ms
65,664 KB
testcase_30 AC 57 ms
46,148 KB
testcase_31 AC 11 ms
12,288 KB
testcase_32 AC 100 ms
85,800 KB
testcase_33 AC 43 ms
30,720 KB
testcase_34 AC 65 ms
58,052 KB
testcase_35 AC 105 ms
99,580 KB
testcase_36 AC 80 ms
69,632 KB
testcase_37 AC 67 ms
64,512 KB
testcase_38 AC 52 ms
47,104 KB
testcase_39 AC 67 ms
44,288 KB
testcase_40 AC 96 ms
73,472 KB
testcase_41 AC 93 ms
80,256 KB
testcase_42 AC 75 ms
68,864 KB
testcase_43 AC 60 ms
45,312 KB
testcase_44 AC 41 ms
40,704 KB
testcase_45 AC 76 ms
67,584 KB
testcase_46 AC 104 ms
112,380 KB
testcase_47 AC 143 ms
112,640 KB
testcase_48 AC 106 ms
112,984 KB
testcase_49 AC 108 ms
112,768 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