結果

問題 No.30 たこやき工場
ユーザー mizunomidorimizunomidori
提出日時 2016-07-02 02:05:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,268 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 80,164 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:17:51
合計ジャッジ時間 1,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

#define N_MAX 100
#define M_MAX 1500

using namespace std;

typedef pair<int, long long> P;

int N, M;
vector<P> g[N_MAX + 1];
long long dp[N_MAX + 1][N_MAX]; // dp[i][j]は製品番号iを1個製造するために購入が必要な製品番号jの個数.
bool used[N_MAX + 1];

void set_dp(int x)
{
    if (used[x]) {
        return;
    }
    used[x] = true;
    if (g[x].size() == 0) {
        for (int i = 1; i < N; i++) {
            dp[x][i] = i == x;
        }
        return;
    }
    for (int i = 0; i < g[x].size(); i++) {
        int y, need;
        tie(y, need) = g[x][i];
        set_dp(y);
        for (int j = 1; j < N; j++) {
            dp[x][j] += need * dp[y][j];
        }
    }
}

int main(void)
{
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        long long p, q, r;
        cin >> p >> q >> r;
        g[r].push_back(P(p, q));
    }
    set_dp(N);
    for (int i = 1; i < N; i++) {
        printf("%lld\n", dp[N][i]);
    }
    return 0;
}
0