QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89705#5665. AA Country and King DreamoonAlanSPWA 77ms3532kbC++14973b2023-03-20 22:50:132023-03-20 22:51:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-20 22:51:55]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:3532kb
  • [2023-03-20 22:50:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+9;
int a[N],T,stk[N],top,n,cnt,p;
bool vis[N];

void dfs(int u,int fa)
{
    if(p==n) return;
    tp:;
    if(a[p+1]==fa) return ++p,void();
    if(a[p+1]) {dfs(a[++p],u);goto tp;}
    if(top&&(stk[top]<fa||2*top-1==cnt))
    {
        a[++p]=stk[top--];
        cnt--;
        // printf("%d %d\n",p,a[p]);
        dfs(a[p],u);
        goto tp;
    }
    else
    {
        cnt--;
        a[++p]=fa;
        return;
    }
}

inline void solve()
{
    scanf("%d",&n);top=cnt=0;p=1;
    int bn=n;
    n=2*n-1;
    for(int i=1;i<=n;i++) vis[i]=false;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),cnt+=(a[i]==0);
    for(int i=1;i<=n;i++) vis[a[i]]=true;
    for(int i=bn;i>=2;i--) if(!vis[i]) stk[++top]=i;
    if(!a[1]) a[1]=1;
    dfs(1,300001);
    for(int i=1;i<=n;i++) printf("%d ",a[i]);
    puts("");
}

int main()
{
    scanf("%d",&T);
    while(T--) solve();
}

詳細信息

Test #1:

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

input:

9
5
1 2 3 2 0 2 1 5 1
5
1 2 3 0 0 2 1 5 1
5
1 2 0 0 0 2 1 5 1
5
1 2 0 0 0 0 1 5 1
5
1 0 0 0 0 0 1 5 1
5
1 0 0 0 0 0 0 5 1
5
1 0 0 0 0 0 0 0 1
5
1 0 0 0 0 0 0 0 0
5
0 0 0 0 0 0 0 0 0

output:

1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 

result:

ok 9 lines

Test #2:

score: -100
Wrong Answer
time: 77ms
memory: 3516kb

input:

28668
2
0 2 1
2
0 0 1
2
0 0 0
2
1 0 1
2
1 0 0
2
1 2 0
3
0 2 1 3 1
3
0 0 1 3 1
3
0 0 0 3 1
3
0 0 0 0 1
3
0 0 0 0 0
3
1 0 1 3 1
3
1 0 0 3 1
3
1 0 0 0 1
3
1 0 0 0 0
3
1 2 0 3 1
3
1 2 0 0 1
3
1 2 0 0 0
3
1 2 1 0 1
3
1 2 1 0 0
3
1 2 1 3 0
3
0 2 3 2 1
3
0 0 3 2 1
3
0 0 0 2 1
3
1 0 3 2 1
3
1 0 0 2 1
3
1 2 ...

output:

1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 3 2 1 
1 300001 3 2 1 
1 3 1 2 1 
1 300001 3 2 1 
1 3 1 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 ...

result:

wrong answer 23rd lines differ - expected: '1 2 3 2 1', found: '1 300001 3 2 1 '