QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#171586 | #6561. Fail Fast | ucup-team134 | WA | 2ms | 9288kb | C++14 | 1.3kb | 2023-09-09 17:15:47 | 2023-09-09 17:15:48 |
Judging History
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];
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);
}
}
int main(){
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++){
int x,par;
scanf("%i %f %i",&x,&p[i],&par);
E[par].pb(i);
c[i]=x;
last[i]=i;
go[i]=0;
}
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;
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: 8400kb
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: 9288kb
input:
4 84 0.716 0 91 0.115 0 19 0.640 1 103 0.455 0
output:
1 3 2 4
result:
wrong answer your plan is not optimal