結果

問題 No.1111 コード進行
ユーザー noritakenoritake
提出日時 2020-07-10 23:13:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,054 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 179,740 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-01 22:40:49
合計ジャッジ時間 5,981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 43 ms
4,384 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;


int N, M, K;
map<int, vector<pair<int, int>>> G;

int dfs(int x, int move, int cost) {

    if (move == N) {
        if (cost == K) {
            return 1;
        } else {
            return 0;
        }
    }

    int cnt = 0;
    for (int i = 0; i < G[x].size(); i++) {
        // 次に向かうところ
        int a = G[x][i].first;

        // コスト
        int b = G[x][i].second;

        cnt += dfs(a, move + 1, cost + b);
    }

    return cnt;
}

int main() {
    cin >> N >> M >> K;

    vector<int> P(M), Q(M), C(M);
    rep(i, M) {
        cin >> P[i] >> Q[i] >> C[i];
        P[i]--;
        Q[i]--;
    }

    set<int> st;
    rep(i, M) {
        st.insert(P[i]);
    }

    rep(i, M) {
        G[P[i]].push_back(make_pair(Q[i], C[i]));
        // G.insert(make_pair(Q[i], C[i]));
    }

    int cnt = 0;
    for (auto x : st) {
        int z = dfs(x, 1, 0);
        cnt += z;
    }
    cout << cnt << endl;
}
0