QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423227 | #6301. Minimum Suffix | zhicheng | WA | 2ms | 10100kb | C++14 | 1.3kb | 2024-05-27 21:41:54 | 2024-05-27 21:41:54 |
Judging History
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]=l-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(!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:;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10036kb
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: 2ms
memory: 10100kb
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: -100
Wrong Answer
time: 1ms
memory: 10056kb
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 2 -1 1 3 1 3 1 2 1 1 1 1 2 2 -1 -1 1 1 2 1 -1 2 1 2 2 -1 2 1 3 1 1 1 1 2 2 1 1 2 2 2 1 2 1 1 1 1
result:
wrong answer 18th numbers differ - expected: '3', found: '2'