結果

問題 No.30 たこやき工場
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-15 21:22:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 837 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 155,276 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:15:13
合計ジャッジ時間 2,194 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define MAX 99999999

int N, M;
vector<int> P(1500), Q(1500), R(1500);
vector<int> cost(100);
vector<vector<pair<int, int>>> e(100);

vector<vector<long long>> dp(150);

vector<long long >dfs(int a){
	if (dp[a].size() != 0) return dp[a];
	vector<long long> ret(N);
	if (cost[a] != 1){
		for (auto i : e[a]){
			vector<long long> add = dfs(i.second);
			for (int j = 0; j < N; j++)
			{
				ret[j] += add[j] * i.first;
			}
		}
	}
	else ret[a] = 1;
	return dp[a] = ret;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		cost[i] = 1;
	}
	for (int i = 0; i < M; i++)
	{
		cin >> P[i] >> Q[i] >> R[i];
		P[i]--; R[i]--;
		cost[R[i]] = MAX;
		e[R[i]].push_back(make_pair(Q[i], P[i]));
	}
	auto ans = dfs(N - 1);
	for (int i = 0; i < N - 1; i++)
	{
		cout << ans[i] << endl;
	}
}

0