QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115622#6506. Chase Game 3jzh#WA 77ms3480kbC++141.7kb2023-06-26 13:33:452023-06-26 13:33:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-26 13:33:49]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:3480kb
  • [2023-06-26 13:33:45]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 5005;


int main() {
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        if (n <= 3) {
            cout << "Yes" << "\n";
            continue;
        }
        bool sud1 = true;
        vector<int> vis(n + 1);
        for (int i = 0; i < n; i++) {
            int tar = i + 1;
            if (abs(a[i] - tar) == 1) {
                vis[i] = 1;
            } else if (abs(a[i] - tar) > 1) {
                sud1 = false;
            }
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (vis[i]) {
                cnt++;
            } else {
                cnt = 0;
            }
            if (cnt >= 3) {
                sud1 = false;
            }
        }
        bool sud2 = true;
        vector<bool> vis2(n + 1);
        for (int i = 0; i < n; i++) {
            int tar = n - i;
            if (abs(a[i] - tar) == 1) {
                vis2[i] = 1;
            } else if (abs(a[i] - tar) > 1) {
                sud2 = false;
            }
        }

        cnt = 0;
        for (int i = 0; i < n; i++) {
            if (vis2[i]) {
                cnt++;
            } else {
                cnt = 0;
            }
            if (cnt >= 3) {
                sud2 = false;
            }
        }
        if(sud1 || sud2){
            cout <<"Yes" <<"\n";
        }
        else{
            cout <<"No" <<"\n";
        }

    }

    return 0;
}
/*
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


 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3480kb

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: 77ms
memory: 3436kb

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
Yes
No
Yes
No
Yes
No
No
No
No
No
No
No
No
Yes
Yes
No
Yes
Yes
No
Yes
No
No
No
Yes
No
No
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
No
No
No
No
No
No
No
Yes
Yes
No
Yes
Yes
Yes
Yes
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
Yes
No
Yes
No
Yes
Yes
No
No
Yes
No
Ye...

result:

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