比赛 20241127 评测结果 RRRRRRRRRR
题目名称 魔法药水 最终得分 0
用户昵称 dick 运行时间 0.161 s
代码语言 C++ 内存使用 4.82 MiB
提交时间 2024-11-27 10:19:54
显示代码纯文本
#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.in","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;
}