QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153196#6561. Fail Fastqzez#WA 22ms72720kbC++141.6kb2023-08-29 16:38:252023-08-29 16:38:26

Judging History

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

  • [2023-08-29 16:38:26]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:72720kb
  • [2023-08-29 16:38:25]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=100+5,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,To[N],fa[N];
struct Node{
	db c;db p;
	Node operator +(const Node &B)const{return (Node){c+B.c*(1-p),(1-p)*(1-B.p)};}
	bool operator <(const Node &B)const{return c/p<B.c/B.p;}
}A[N];
deque<int> q[N];
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
void Solve(){
	int i,j;scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%lf%lf%d",&A[i].c,&A[i].p,&To[i]),q[i].emplace_back(i);
	iota(fa+1,fa+n+1,1);
	set<pair<Node,int> > f;
	for(i=1;i<=n;i++) f.emplace(A[i],i);
	while(!f.empty()){
		auto p=*f.begin();f.erase(f.begin());
		int ff=GF(To[p.se]);
		f.erase(make_pair(A[ff],ff));
		A[ff]=A[ff]+A[p.se];
		if(q[ff].size()>q[p.se].size()){
			while(!q[p.se].empty()) q[ff].emplace_back(q[p.se].front()),q[p.se].pop_front();
		} else{
			while(!q[ff].empty()) q[p.se].emplace_front(q[ff].back()),q[ff].pop_back();swap(q[ff],q[p.se]);
		}
		if(ff) f.emplace(A[ff],ff);
	}
	for(int i:q[0]) printf("%d\n",i);
}
int main(){
	int t;
	// scanf("%d",&t);
	t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 71712kb

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: 22ms
memory: 72720kb

input:

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

output:

4
2
1
3

result:

wrong answer your plan is not optimal