记录编号 597388 评测结果 WAAAAAAAAA
题目名称 魔法药水 最终得分 90
用户昵称 Gravatardick 是否通过 未通过
代码语言 C++ 运行时间 0.158 s
提交时间 2024-11-27 12:06:56 内存使用 4.82 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
struct ingredient
{
	int material1=0;
	int material2=0;
}; 
struct magic_potion
{
	int sale_price=0;
	int min_cost=0;
	long long mincost_plannumbers=0;
	long long combine_plannumbers=0;
	ingredient ing[10005];
} mp[N];
int n,x,y,z;
int main()
{
	freopen("msyrup.in","r",stdin);
	freopen("msyrup.out","w",stdout);
	cin>>n;
	for(int i=0;i<=n-1;i++){
		cin>>mp[i].sale_price;
		mp[i].min_cost=mp[i].sale_price;
		mp[i].mincost_plannumbers=1;
	}
	while(cin>>x){
		cin>>y;
		cin>>z;
		mp[z].combine_plannumbers++;
		mp[z].ing[mp[z].combine_plannumbers].material1=x;
		mp[z].ing[mp[z].combine_plannumbers].material2=y;
	}
	for(int i=n-1;i>=0;i--){
		for(int cpn=1;cpn<=mp[i].combine_plannumbers;cpn++){
			int m1=mp[i].ing[cpn].material1;
			int m2=mp[i].ing[cpn].material2;
			if(mp[m1].min_cost+mp[m2].min_cost==mp[i].min_cost){
				mp[i].mincost_plannumbers = mp[i].mincost_plannumbers + (mp[m1].mincost_plannumbers * mp[m2].mincost_plannumbers);
			}
			else{
				if(mp[m1].min_cost+mp[m2].min_cost<mp[i].min_cost){
					mp[i].min_cost=mp[m1].min_cost+mp[m2].min_cost;
					mp[i].mincost_plannumbers= mp[m1].mincost_plannumbers * mp[m2].mincost_plannumbers;
				}
			}
		}
	}
	cout<<mp[0].min_cost<<" "<<mp[0].mincost_plannumbers;
}