QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#382930#6506. Chase Game 3paoxiaomo#WA 18ms3780kbC++202.7kb2024-04-08 20:19:342024-04-08 20:19:35

Judging History

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

  • [2024-04-08 20:19:35]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3780kb
  • [2024-04-08 20:19:34]
  • 提交

answer

// #include <bits/stdc++.h>
// #define int long long
// using namespace std;
// using vi = vector<int>;
// #define endl '\n'

// void solve()
// {
//     int n,nu=0;
//     cin >> n;
//     vector<int> v(n + 1);
//     bool is1 = 1, is2 = 1, is3 = 1;
//     for (int i = 1; i <= n; i++)
//     {
//         cin >> v[i];
//     }
//     for (int i = 1; i <= n; i++)
//     {

//         if (v[i] != i)
//             is1 = 0;
//         if (v[i] != n - i + 1)
//             is2 = 0;
//     }
//     auto solve=[&]()->bool{
//        set<int>st;
//        for(int i=1;i<=n;i++)st.insert(i);
//         for (int i = 1; i <= n; i++)
//         {
//             set<int>cover;
//             if(i!=1){
//                     cover.insert(v[i-1]);
//             }
//             if(i!=n){
//                     cover.insert(v[i+1]);
//             }
//             if(!cover.count())
//         }
//     };

//     if (n == 2 || n == 3 || is1 || is2 || is3)
//     {
//         cout << "Yes" << endl;
//     }
//     else
//     {
//         cout << "No" << endl;
//     }
// }
// signed main()
// {
//     ios::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);

//     int T;
//     cin >> T;
//     while (T--)
//         solve();
// }
#include <bits/stdc++.h>
#define int long long
using namespace std;
using vi = vector<int>;
#define endl '\n'

void solve()
{
    int n, nu = 0;
    cin >> n;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    auto check = [&]()
    {
        vi pos;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == i)
                continue;
            else if (v[i] == i + 1)
            {
                if (i == n)
                    return 0;
                if (v[i + 1] == i)
                    pos.push_back(i);
                else
                    return 0;
                i++;
            }
            else
                return 0;
        }
        for (int i = 1; i < pos.size(); i++)
        {
            if (pos[i] - pos[i - 1] >= 3)
                void();
            else
                return 0;
        }
        return 1;
    };

    // cout << check();

    if (n == 2 || n == 3)
    {
        cout << "Yes" << endl;
    }
    else
    {
        if (check())
            return cout << "Yes" << endl, void();
        reverse(v.begin() + 1, v.end());
        if (check())
            return cout << "Yes" << endl, void();
        cout << "No" << endl;
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int T;
    cin >> T;
    while (T--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3780kb

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: 18ms
memory: 3476kb

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]