QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#199674 | #7346. Frogs | whsyhyyh# | WA | 0ms | 3628kb | C++14 | 1015b | 2023-10-04 13:40:05 | 2023-10-04 13:40:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+9;
int n,a[N];
int b[N];
bool flag;
int stk[N];
int top;
struct info {
int l,r;
}A[N<<2];
int ans[N];
int cnt;
int xx;
int main(){
scanf("%d",&n);
for(int i=1; i<n; ++i) scanf("%d",&a[i]);
for(int i=1; i<=n; ++i) {
b[i]=a[i]-a[i-1];
if(b[i]!=2&&b[i]!=-2&&b[i]!=0)flag=true;
}
if(flag)puts("No");
else {
for(int i=1; i<=n; ++i) {
if(b[i]==2)stk[++top]=i,stk[++top]=i;
else if(b[i]==-2) {
while(b[i]<0&&top) {
A[++cnt]=(info)<%stk[top],i%>;
--top;
b[i]++;
}
if(b[i]!=0){flag=true;break;}
}else if(b[i]==0) {
if(top)A[++cnt]=(info)<%stk[top],i%>,top--;
else {flag=true;break;}
stk[++top]=i;
}
}
if(flag) {puts("No");return 0;}
for(int i=1; i<=cnt; ++i) {
if(!ans[A[i].l])ans[A[i].l]=A[i].r;
else if(!ans[A[i].r])ans[A[i].r]=A[i].l;
}
puts("Yes");
for(int i=1; i<=n; ++i)printf("%d ",ans[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
5 2 4 2 2
output:
Yes 4 3 2 5 1
result:
ok Correct answer.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
4 1 2 3
output:
No
result:
ok Correct answer.
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
2 0
output:
No
result:
wrong answer Expected YES, found NO on the first line