QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709016#7455. stcmDengDuckWA 83ms7320kbC++141.2kb2024-11-04 10:50:262024-11-04 10:50:28

Judging History

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

  • [2024-11-04 10:50:28]
  • 评测
  • 测评结果:WA
  • 用时:83ms
  • 内存:7320kb
  • [2024-11-04 10:50:26]
  • 提交

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;
	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('-');
	if(Mid+1<=R)for(int i=Mid+1;i<=R;i++)printf("+%d",B[i]);
	Work(LS,L,Mid-1);
	if(Mid+1<=R)for(int i=Mid+1;i<=R;i++)putchar('-');		
	if(L<=Mid-1)for(int i=L;i<=Mid-1;i++)printf("+%d",B[i]);
	Work(RS,Mid+1,R);
	if(L<=Mid-1)for(int i=L;i<=Mid-1;i++)putchar('-');
}
int main()
{
	while(~scanf("%d",&n))
	{
		TOT=0,S.clear();
		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');
	}
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 83ms
memory: 7320kb

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 -1 / -1 / -1