QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89712 | #5665. AA Country and King Dreamoon | AlanSP | WA | 34ms | 3592kb | C++14 | 1.5kb | 2023-03-20 23:16:53 | 2023-03-20 23:16:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=6e5+9;
int a[N],T,stk[N],top,n,cnt,p;
vector<int> chd;
bool vis[N],ichd[N];
inline bool check(int u,int fa)
{
if(u==1&&!chd.empty()) return stk[top]<chd[0];
else return stk[top]<fa;
}
void dfs(int u,int fa)
{
// system("pause");
tp:;
if(p==n) return;
if(a[p+1]==fa) return ++p,void();
if(a[p+1]) {dfs(a[++p],u);goto tp;}
if(top&&(check(u,fa)||2*top-1==cnt))
{
a[++p]=stk[top--];
cnt--;
dfs(a[p],u);
goto tp;
}
else
{
cnt--;
if(u==1)
{
if(chd[0]==a[p+2]) a[++p]=chd[1];
else a[++p]=chd[0];
// printf("%d %d\n",u,a[p]);
dfs(a[p],u);
goto tp;
}
else a[++p]=fa;
return;
}
// printf("%d %d %d\n",u,fa,p);
}
inline void solve()
{
chd.clear();
scanf("%d",&n);top=cnt=0;p=1;
int bn=n;
n=2*n-1;
for(int i=1;i<=n;i++) vis[i]=ichd[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;
for(int i=1;i<=n;i++)
if(!ichd[a[i]]&&(a[i+1]==1||a[i-1]==1)&&a[i])
chd.push_back(a[i]),ichd[a[i]]=true;
sort(chd.begin(),chd.end());
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: 0ms
memory: 3504kb
input:
9 5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