QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#510142#6301. Minimum SuffixyyyyxhWA 0ms9692kbC++141.4kb2024-08-08 21:29:032024-08-08 21:29:03

Judging History

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

  • [2024-08-08 21:29:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9692kb
  • [2024-08-08 21:29:03]
  • 提交

answer

#include <cstdio>
#include <algorithm>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=3000003;
int p[N],n;
int stk[N],tp;
bool eq[N];int las[N];
int a[N];
void solve(){
	n=read();
	for(int i=1;i<=n;++i) p[i]=read();
	tp=0;
	for(int i=1;i<=n;++i){
		stk[++tp]=i;
		while(tp&&stk[tp]>p[i]) --tp;
		if(!tp||stk[tp]!=p[i]){puts("-1");return;}
	}
	stk[tp+1]=n+1;
	for(int i=1;i<=tp;++i){
		int ps=stk[i];
		for(int x=stk[i]+1;x<stk[i+1];++x){
			las[x]=ps;
			if(p[x]==stk[i]){eq[x]=0,ps=p[x];continue;}
			if(p[x]-x==p[ps]-ps){eq[x]=1,++ps;continue;}
			puts("-1");return;
		}
	}
	for(int i=tp;i;--i){
		bool cmp=i<tp;
		if(cmp) a[stk[i]]=a[stk[i+1]];
		else a[stk[i]]=1;
		for(int x=stk[i]+1,y=stk[i+1]+1;x<stk[i+1];++x,++y){
			if(eq[x]) a[x]=a[las[x]];
			else a[x]=a[las[x]]+1;
			if(cmp&&y<stk[i+2]&&a[x]<a[y]){
				a[x]=a[y];
				int t=x;
				if(eq[t]) cmp=0;
				while(true){
					a[t]=a[y];
					if(t>stk[i]&&eq[t]) t=las[t];
					else break;
				}
				a[x]=max(a[x],a[y]);
			}
			if(cmp&&y<stk[i+2]&&a[x]>a[y]) cmp=0;
		}
		if(cmp&&stk[i+2]-stk[i+1]>stk[i+1]-stk[i]){
			int p=stk[i+1]-1;
			while(p>stk[i]&&eq[p]) --p;
			++a[p];
		}
	}
	printf("%d\n",eq[2]);
	for(int i=1;i<=n;++i) printf("%d ",a[i]);
	putchar('\n');
}
int main(){
	int tc=read();
	while(tc--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9692kb

input:

6
3
1 1 1
3
1 1 2
3
1 1 3
3
1 2 1
3
1 2 2
3
1 2 3

output:

0
1 2 2 
-1
0
1 2 1 
1
1 1 2 
1
2 1 2 
1
1 1 1 

result:

wrong answer 1st numbers differ - expected: '1', found: '0'