QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708994#7455. stcmDengDuckWA 74ms7604kbC++141.2kb2024-11-04 10:35:532024-11-04 10:35:53

Judging History

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

  • [2024-11-04 10:35:53]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:7604kb
  • [2024-11-04 10:35:53]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+5;
int n,Dfn[N],B[N],Sz[N],TOT;
vector<int>E[N],S;
void Dfs(int x)
{
	Dfn[x]=++TOT;B[TOT]=x,Sz[x]=1;
	S.pb(TOT);
	for(int i:E[x])
	{
		Dfs(i);
		Sz[x]+=Sz[i];
	}
}
void Work(vector<int>&S,int L,int R)
{
	if(S.empty())return;
//	cout<<endl<<L<<" "<<R<<endl;
	if(L==R)return printf("=%d",B[L]),void();
	vector<int>LS,RS;
	int Mid=L+R>>1,l=L-1,r=R+1;
	for(int i:S)
	{
		if(i+Sz[B[i]]-1<=Mid)LS.pb(i);
		else if(Mid<i)RS.pb(i);
		else
		{
			while(l<i-1)printf("+%d",B[++l]);
			while(r>i+Sz[B[i]])printf("+%d",B[--r]);
			printf("=%d",B[i]);
		}
	}
	for(int i=L;i<=l;i++)putchar('-');
	for(int i=r;i<=R;i++)putchar('-');

	for(int i=Mid+1;i<=R;i++)printf("+%d",B[i]);
	Work(LS,L,Mid);
	for(int i=Mid+1;i<=R;i++)putchar('-');		
	for(int i=L;i<=Mid;i++)printf("+%d",B[i]);
	Work(RS,Mid+1,R);
	for(int i=L;i<=Mid;i++)putchar('-');
}
int main()
{
	while(~scanf("%d",&n))
	{
		TOT=0;
		for(int i=1;i<=n;i++)
		{
			Dfn[i]=B[i]=Sz[i]=0;
			E[i].clear();
		}
		for(int i=2,x;i<=n;i++)
		{
			scanf("%d",&x);
			E[x].pb(i);
		}
		Dfs(1);
		Work(S,1,n);
		putchar('!'),putchar('\n');
	}
	
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 74ms
memory: 7604kb

input:

1000
1 1 2 1 1 2 2 7 2 7 3 11 10 6 4 8 10 13 16 2 19 7 6 18 6 2 16 27 21 14 6 14 14 29 12 13 3 27 28 27 2 34 26 27 44 14 30 25 7 50 47 1 36 24 4 32 10 20 53 52 61 23 43 39 2 15 47 9 14 54 48 53 36 14 14 66 76 55 17 67 21 22 18 25 67 75 7 48 21 6 35 11 31 41 63 28 6 98 51 3 29 52 102 77 27 58 39 64 9...

output:

=1+1+772+569+940+882+812+494+243+968+773+732+727+570+441+905+754+435+980+665+426+323+843+798+622+412+206+177+619+590+175+994+778+129+873+691+650+523+468+136+73+531+195+60+53+661+548+368+983+837+319+601+421+362+342+696+678+481+291+202+874+649+521+764+247+663+598+347+346+936+400+290+192+167+473+745+40...

result:

wrong answer 15192 / -1 / -1