結果

問題 No.30 たこやき工場
ユーザー hotpepsihotpepsi
提出日時 2015-03-30 02:32:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 947 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 68,644 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:15:07
合計ジャッジ時間 1,385 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cstring>

using namespace std;

typedef long long LL;
typedef vector<LL> LLVec;
LL memo[256];
LLVec req_index[256];
LLVec req_count[256];

LL calc(int index) {
	LL &res = memo[index];
	if (res >= 0) {
		return res;
	}
	res = 0;
	for (LL i = 0; i < req_index[index].size(); ++i) {
		res += calc(req_index[index][i]) * req_count[index][i];
	}
	return res;
}

int main(int argc, char *argv[]) {
	string s;
	getline(cin, s);
	LL N = atoi(s.c_str());
	getline(cin, s);
	LL M = atoi(s.c_str());
	LL gen[256] = {};
	for (LL i = 0; i < M; ++i) {
		getline(cin, s);
		stringstream ss(s);
		int P, Q, R;
		ss >> P >> Q >> R;
		req_index[P - 1].push_back(R - 1);
		req_count[P - 1].push_back(Q);
		gen[R - 1] = 1;
	}
	memset(memo, -1, sizeof(memo));
	memo[N - 1] = 1;
	for (LL i = 0; i < N - 1; ++i) {
		LL c = gen[i] ? 0 : calc(i);
		cout << c << endl;
	}
	return 0;
}
0