結果
| 問題 | No.30 たこやき工場 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-10-29 17:54:42 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 5,000 ms | 
| コード長 | 799 bytes | 
| コンパイル時間 | 786 ms | 
| コンパイル使用メモリ | 60,416 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-21 05:23:02 | 
| 合計ジャッジ時間 | 1,474 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%d%d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |                 scanf("%d%d%d",&P,&Q,&R);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~
            
            ソースコード
#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));
}
            
            
            
        