QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#517005 | #6561. Fail Fast | ucup-team2307# | WA | 3ms | 17084kb | C++20 | 2.7kb | 2024-08-13 02:44:23 | 2024-08-13 02:44:23 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long ll;
#define int ll
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
int n;
double c[100500];
double p[100500];
vector<int> g[100500];
struct Node
{
double c;
double p;
int l;
int r;
};
int m = 0;
Node t[200500];
struct Id
{
int i;
};
bool operator < (Id x, Id y){ return tuple(t[x.i].p/t[x.i].c) > tuple(t[y.i].p/t[y.i].c); }
set<Id> st[200500];
void process(int v, int u)
{
// cout<<v<<" "<<u<<" "<<st[v].size()<<"\n";
while (st[v].size() > 0 && !(Id{u} < *st[v].begin()) )
{
auto vr = (*st[v].begin()).i;
st[v].erase(st[v].begin());
t[m].c = t[u].c + t[vr].c * (1-t[u].p);
t[m].p = t[u].p + t[vr].p - t[u].p * t[vr].p;
t[m].l = u;
t[m].r = vr;
u = m;
m++;
}
st[v].insert(Id{u});
}
int dfs(int v)
{
// cout<<v<<endl;
if (g[v].empty())
{
t[m].c = c[v];
t[m].p = p[v];
t[m].l = -1;
t[m].r = v;
st[v].insert(Id{m});
m++;
return v;
}
vector<int> vec;
for (int i : g[v])
vec.pb(dfs(i));
pair<int, int> mx = {-1, -1};
for (int i : vec)
if (int(g[i].size()) > mx.fi)
{
mx.fi = g[i].size();
mx.se = i;
}
int u = mx.se;
for (int i : vec)
if (i!=u)
{
for (auto id : st[i])
st[u].insert(id);
}
t[m].c = c[v];
t[m].p = p[v];
t[m].l = -1;
t[m].r = v;
m++;
process(u, m-1);
// cout<<v<<" -> ";
// for (auto id : st[u])
// {
// int x = id.i;
// cout<<t[x].c<<" "<<t[x].p<<" "<<t[x].l<<" "<<t[x].r<<", ";
// }
// cout<<"\n";
return u;
}
vector<int> ans;
void Run(int v)
{
if (t[v].l == -1)
{
ans.pb(t[v].r);
return;
}
Run(t[v].l);
Run(t[v].r);
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for (int i=1; i<=n; i++)
{
int x;
cin>>c[i]>>p[i]>>x;
// c[i] = rand()%10+1;
// p[i] = (rand()%10)/20.0+0.25;
// x = rand()%i;
g[x].pb(i);
}
c[0] = 1e18;
p[0] = 1e-18;
int r = dfs(0);
for (auto id : st[r])
Run(id.i);
// cout<<st[r].size()<<"\n";
for (int i : ans)
if (i > 0)
cout<<i<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 17084kb
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: 3ms
memory: 16968kb
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