QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423243#6301. Minimum SuffixzhichengWA 2ms10060kbC++141.4kb2024-05-27 21:48:442024-05-27 21:48:45

Judging History

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

  • [2024-05-27 21:48:45]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10060kb
  • [2024-05-27 21:48:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3000010;
int m,a[N],last[N],pre[N],p[N],val[N],s[N];
int las(int x){
	if(x>m){
		return 0;
	}
	return last[x];
}
int main(){
	int t,n,l,r,len,gt,now;
	scanf("%d",&t);
	while(t--){
		m=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&p[i]);
		}
		r=n;
		while(r>=1){
			l=p[r];
			val[l]=1;
			for(int i=l;i<=r;i++){
				if(p[i]<l){
					printf("-1\n");
					goto lass;
				}
			}
			len=1;
			for(int i=l+1;i<=r;i++){
				pre[i]=i-len;
				if(p[i]==l){
					val[i]=1;
					len=i-l+1;
				}
				else if(i-p[i]==i-len-p[i-len]){
					val[i]=0;
				}
				else{
					printf("-1\n");
					goto lass;
				}
			}
			gt=0;
			s[l]=las(1);
			for(int i=l+1;i<=r;i++){
				s[i]=s[pre[i]]+val[i];
				if(s[i]>las(i-l+1)){
					gt=1;
				}
				if(!gt&&s[i]<las(i-l+1)){
					if(val[i]==0){
						s[i]=las(i-l+1);
					}
					else{
						now=i;
						while(val[now]!=1){
							now--;
						}
						i=now;
						s[i]++;
						gt=1;
					}
				}
			}
			if(!gt&&r-l+1<m){
				now=r;
				while(val[now]!=1){
					now--;
				}
				s[now]++;
				for(int i=now+1;i<=r;i++){
					s[i]=s[pre[i]]+val[i];
				}
			}
			m=r-l+1;
			for(int i=l;i<=r;i++){
				last[i-l+1]=s[i];
			}
			r=l-1;
		}
		for(int i=1;i<=n;i++){
			printf("%d ",s[i]+1);
		}
		printf("\n");
		lass:;
	}
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9908kb

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:

1 2 2 
-1
1 2 1 
1 1 2 
2 1 2 
1 1 1 

result:

ok 16 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 10060kb

input:

2
2
1 1
2
1 2

output:

1 2 
1 1 

result:

ok 4 number(s): "1 2 1 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 9968kb

input:

24
4
1 1 1 1
4
1 1 1 2
4
1 1 1 3
4
1 1 1 4
4
1 1 2 1
4
1 1 2 2
4
1 1 2 3
4
1 1 2 4
4
1 1 3 1
4
1 1 3 2
4
1 1 3 3
4
1 1 3 4
4
1 2 1 1
4
1 2 1 2
4
1 2 1 3
4
1 2 1 4
4
1 2 2 1
4
1 2 2 2
4
1 2 2 3
4
1 2 2 4
4
1 2 3 1
4
1 2 3 2
4
1 2 3 3
4
1 2 3 4

output:

1 2 2 2 
-1
-1
1 2 2 1 
-1
-1
-1
-1
1 2 1 3 
-1
1 2 1 2 
1 2 1 1 
1 1 2 2 
-1
-1
1 1 2 1 
-1
2 1 2 2 
-1
2 1 2 1 
1 1 1 2 
2 1 1 2 
2 2 1 2 
1 1 1 1 

result:

ok 63 numbers

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 9904kb

input:

120
5
1 1 1 1 1
5
1 1 1 1 2
5
1 1 1 1 3
5
1 1 1 1 4
5
1 1 1 1 5
5
1 1 1 2 1
5
1 1 1 2 2
5
1 1 1 2 3
5
1 1 1 2 4
5
1 1 1 2 5
5
1 1 1 3 1
5
1 1 1 3 2
5
1 1 1 3 3
5
1 1 1 3 4
5
1 1 1 3 5
5
1 1 1 4 1
5
1 1 1 4 2
5
1 1 1 4 3
5
1 1 1 4 4
5
1 1 1 4 5
5
1 1 2 1 1
5
1 1 2 1 2
5
1 1 2 1 3
5
1 1 2 1 4
5
1 1 2 ...

output:

1 2 2 2 2 
-1
-1
-1
1 2 2 2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 2 1 3 
-1
-1
1 2 2 1 2 
1 2 2 1 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 1 3 2 
-1
-1
-1
1 2 1 3 1 
-1
-1
-1
-1
-1
1 2 1 2 2 
-1
1 3 1 2 2 
-1
1 2 1 2 1 
-1
-1
1 2 1 1 2 
2 3 2 1 2 
1 2 1 1 1 
1 1 2 2 2 
-1
-1...

result:

wrong answer 143rd numbers differ - expected: '2', found: '1'