QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89705 | #5665. AA Country and King Dreamoon | AlanSP | WA | 77ms | 3532kb | C++14 | 973b | 2023-03-20 22:50:13 | 2023-03-20 22:51:55 |
Judging History
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 '