結果

問題 No.30 たこやき工場
ユーザー ace_amuroace_amuro
提出日時 2021-09-03 03:20:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,110 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 72,748 KB
実行使用メモリ 7,732 KB
最終ジャッジ日時 2023-08-20 18:38:21
合計ジャッジ時間 7,458 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int MR=105;
const int NR=1e6+5;
typedef long long LL;
int n,m;
LL p[MR];//价格
bool israw[MR];//是否为原材料
int v[MR][MR];
//v[a][b]=c表示生产a需要c个b
struct P
{
	LL cnt[MR];
	P(){
		for(int i=0;i<MR;i++) cnt[i]=0;
	}

	P operator += (const P & b){
		for(int i=0;i<MR;i++) cnt[i]+=b.cnt[i];
		return *this;
	}

	P operator * (const int & k) const{
		P b;
		for(int i=0;i<MR;i++) b.cnt[i]=k*cnt[i];
		return b;
	}
};
P cost[MR];
bool vis[MR];
P dfs(int x){
	//if(vis[x]) return cost[x];
	if(israw[x]) {
		vis[x]=1;
		cost[x].cnt[x]=1;
		return cost[x];
	}
	P sum;
	for(int i=1;i<=n;i++){
		if(v[x][i]==0) continue;
		sum+=dfs(i)*v[x][i];
	}
	vis[x]=1;
	return sum;
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		israw[i]=1;
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		int a,b,c;
		scanf("%d%d%d",&b,&c,&a);
		v[a][b]=c;
		israw[a]=0;
	}
	P ans=dfs(n);
	for(int i=1;i<=n-1;i++){
		printf("%lld\n",ans.cnt[i]);
	}
	
    return 0;
}
0