QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244246#6506. Chase Game 3uicereWA 59ms14328kbC++141002b2023-11-08 22:12:112023-11-08 22:12:11

Judging History

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

  • [2023-11-08 22:12:11]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:14328kb
  • [2023-11-08 22:12:11]
  • 提交

answer

#include<iostream>
#include<vector>
using namespace std;
const int N=4e5+8;
int p[N];
bool dgz[N],dgy[N];
vector<int> e[N];
void solve(){
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        dgz[i]=dgy[i]=0;
        e[i].clear();
    }
    for(int i=1;i<=n;i++) cin>>p[i];
    if(n<=3){
        puts("Yes");
        return ;
    } 
    for(int i=1;i<n;i++){
        e[p[i]].push_back(p[i+1]);
        e[p[i+1]].push_back(p[i]);
    }
    for(int i=1;i<=n;i++){
        for(auto v:e[i]){
            if(v<i) dgz[i]=true;
            if(v>i) dgy[i]=true;
        }
        if(i==1){
            if(dgy[i]) continue;
            else {puts("No");return ;}
        }
        else if(i==n){
            if(dgz[i]) continue;
            else {puts("No");return ;}
        }
        else if(dgz[i]&&dgy[i]) continue;
        else{puts("No");return ;}
    }
    puts("Yes");
    return ;
}
int main(){
    int T;
    cin>>T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 14328kb

input:

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

output:

Yes
Yes
No
No
Yes

result:

ok 5 token(s): yes count is 3, no count is 2

Test #2:

score: 0
Accepted
time: 3ms
memory: 14260kb

input:

8
2
1 2
2
2 1
3
1 2 3
3
3 1 2
3
2 1 3
3
2 3 1
3
3 2 1
3
1 3 2

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes

result:

ok 8 token(s): yes count is 8, no count is 0

Test #3:

score: -100
Wrong Answer
time: 59ms
memory: 13412kb

input:

100000
4
4 1 3 2
4
3 2 4 1
4
3 2 1 4
4
2 4 3 1
4
1 2 3 4
4
2 3 1 4
4
1 3 4 2
4
3 4 1 2
4
1 3 2 4
4
1 4 3 2
4
3 4 2 1
4
3 2 4 1
4
4 2 3 1
4
3 2 4 1
4
4 1 2 3
4
3 2 1 4
4
4 1 3 2
4
1 3 4 2
4
1 4 2 3
4
2 4 3 1
4
2 3 1 4
4
4 2 3 1
4
2 1 3 4
4
3 1 2 4
4
1 2 3 4
4
4 3 2 1
4
3 4 1 2
4
1 3 2 4
4
4 2 1 3
4
3...

output:

No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
...

result:

wrong answer expected YES, found NO [1st token]