QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#199787 | #7346. Frogs | SolitaryDream# | WA | 3ms | 8444kb | C++20 | 1.2kb | 2023-10-04 14:02:47 | 2023-10-04 14:02:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1e3+7;
int n,a[N];
vector<int> v[N];
int p[N];
int w[N];
void dfs(int l,int r,int d)
{
int t=(d+1)*2;
if(l>r)
return;
vector<int> s;
s.push_back(l);
auto it=upper_bound(v[t].begin(),v[t].end(),l);
while(it<v[t].end()&&*it<r)
s.push_back(*it),it++;
s.push_back(r);
for(int i=0;i<s.size();i++)
{
p[s[i]]=s[(i+1)%s.size()];
if(i<s.size())
dfs(s[i]+1,s[i+1]-1,d+1);
}
}
int main()
{
scanf("%d",&n);
for(int i=1;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=2;i<n;i++)
if(a[i-1]==a[i])
v[a[i]].push_back(i);
dfs(1,n,0);
for(int i=1;i<=n;i++)
{
int l=i,r=p[i];
if(l>r)
swap(l,r);
w[l]++,w[r]--;
}
for(int i=1;i<=n;i++)
w[i]+=w[i-1];
bool ok=1;
for(int i=1;i<n;i++)
if(w[i]!=a[i])
ok=0;
for(int i=1;i<=n;i++)
if(!p[i])
ok=0;
if(!ok)
puts("NO");
else
{
puts("YES");
for(int i=1;i<=n;i++)
printf("%d%c",p[i]," \n"[i==n]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 8444kb
input:
5 2 4 2 2
output:
YES 4 3 2 5 1
result:
wrong answer Line [name=verdict] equals to "YES", doesn't correspond to pattern "Yes|No"