QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#171726#6561. Fail Fastucup-team134WA 2ms8672kbC++142.0kb2023-09-09 17:31:102023-09-09 17:31:10

Judging History

你现在查看的是最新测评结果

  • [2023-09-09 17:31:10]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8672kb
  • [2023-09-09 17:31:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ldb double
#define pb push_back

const int N=100050;

vector<int> E[N];
ldb c[N],p[N];

set<pair<ldb,int>>* all[N];
int go[N],last[N],par[N];

void Compress(int u){
	set<pair<ldb,int>>* ch=new set<pair<ldb,int>>();
	for(int v:E[u]){
		Compress(v);
		ch->insert({(1-p[v])/c[v],v});
	}
	while(ch->size() && (1-p[u])/c[u]<ch->rbegin()->first){
		int v=ch->rbegin()->second;
		ldb newP=p[u]*p[v];
		ldb newC=c[u]+p[u]*c[v];
		c[u]=newC;
		p[u]=newP;

		ch->erase(--ch->end());
		if(all[v]->size()>ch->size()){
			swap(ch,all[v]);
		}
		for(auto p:*all[v]){
			ch->insert(p);
		}
		delete all[v];

		go[last[u]]=v;
		last[u]=last[v];
	}

	all[u]=ch;
}

vector<pair<ldb,int>> ord;
void DFS(int u){
	for(auto p:*all[u]){
		ord.pb({-p.first,p.second});
		DFS(p.second);
	}
}

void Brute(int n){
	vector<int> per;
	for(int i=1;i<=n;i++)per.pb(i);
	ldb ans=1e100;
	vector<int> sol;
	vector<int> pos(n+1,0);
	do{
		ldb now=0,sum=0;
		for(int i=0;i<per.size();i++){
			sum+=c[per[i]];
			now+=sum*(1-p[per[i]]);
			pos[per[i]]=i;
		}
		bool ok=true;
		for(int i=0;i<per.size();i++){
			if(par[per[i]]!=0 && pos[par[per[i]]]>i){
				ok=false;
			}
		}
		if(ok && now<ans){
			ans=now;
			sol=per;
		}
	}while(next_permutation(per.begin(),per.end()));
	printf("Brute ans=%f\n",ans);
	for(int i:sol)printf("%i\n",i);
	printf("\n");
}

int main(){
	int n;
	scanf("%i",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%i %lf %i",&x,&p[i],&par[i]);
		//printf("%f\n",p[i]);
		p[i]=1.0-p[i];
		//printf("%f\n",p[i]);
		E[par[i]].pb(i);
		c[i]=x;
		last[i]=i;
		go[i]=0;
	}

	//Brute(n);

	for(int root:E[0]){
		Compress(root);
	}
	for(int root:E[0]){
		ord.pb({-(1-p[root])/c[root],root});
		DFS(root);
	}
	stable_sort(ord.begin(),ord.end());
	for(auto p:ord){
		int u=p.second;
		//printf("%.12f ",-p.first);
		for(int z=u;z;z=go[z]){
			printf("%i\n",z);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7860kb

input:

4
100 0.5 0
200 0.1 1
10 0.5 2
10 0.9 0

output:

4
1
2
3

result:

ok correct

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 8672kb

input:

4
84 0.716 0
91 0.115 0
19 0.640 1
103 0.455 0

output:

1
3
4
2

result:

wrong answer your plan is not optimal