結果

問題 No.30 たこやき工場
ユーザー cielciel
提出日時 2015-10-29 17:54:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 799 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 74,432 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 05:16:42
合計ジャッジ時間 1,513 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <vector>
#include <unordered_map>
#include <cstdio>
using namespace std;

namespace std{
	template<typename I>
	class hash<pair<I,I>>{
		public:
		size_t operator()(const pair<I,I> &p) const {return hash<long long>() (((long long)(p.first))<<32|p.second);}
	};
}

unordered_map<pair<int,int>,int>m;
unordered_map<pair<int,int>,long long>memo;
vector<int> f;
int N;

long long dfs(int i,int j){
	long long r=0;
	pair<int,int> p=make_pair(i,j);
	if(memo.find(p)!=memo.end())return memo[p];
	if(i==j)return !f[i];
	for(int k=0;k<N;k++)if(m.find({i,k})!=m.end())r+=dfs(k,j)*m[{i,k}];
	return memo[p]=r;
}
int main(){
	int M,P,Q,R;
	scanf("%d%d",&N,&M);
	f.resize(N);
	for(;M--;){
		scanf("%d%d%d",&P,&Q,&R);
		m[{R-1,P-1}]=Q;
		f[R-1]=1;
	}
	for(int i=0;i<N-1;i++)printf("%lld\n",dfs(N-1,i));
}
0