QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#544364#6506. Chase Game 3haze#WA 11ms3560kbC++202.1kb2024-09-02 15:41:452024-09-02 15:41:46

Judging History

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

  • [2024-09-02 15:41:46]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3560kb
  • [2024-09-02 15:41:45]
  • 提交

answer

/*

Author: Haze

2024/9/2

*/

#include <bits/stdc++.h>

#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
#define drep(i, r, l) for(int i = (r); i >= (l); -- i)
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
typedef long long ll;
#define int long long
inline ll readL() {
    ll s = 0;
    bool fl = false;
    char ch = (char) getchar();
    while (!isdigit(ch)) {
        if (ch == '-')fl = true;
        ch = (char) getchar();
    }
    while (isdigit(ch)) {
        s = s * 10 + (ch ^ 48);
        ch = (char) getchar();
    }
    return fl ? -s : s;
}

inline int read() {
    return (int) (readL());
}

const int mod = 1000000000 + 7;
const int itinf = 1000000999;
const ll llinf = 2e18;
const int N = 500099;

void solve() {
    int n = read();
    vector<int>a(n);
    irep(i, 0, n - 1){
        a[i] = read() - 1;
    }
    irep(i, 1, n - 1){
        if(a[i] - a[i - 1] > 2 || a[i] - a[i - 1] < -2){
            cout << "No\n";
            return;
        }
    }
//    int ok = 1;
    vector<int>b;
    for(int i = 0; i < n - 1; ++ i){
        int d = a[i + 1] - a[i];
        b.push_back(d);
    }
    int S = -1000000000;
    int sp = -1000000000;
    int last = S;
    auto nxt = [](int x){
        if(x > 0)return -(x + 1);
        return -x + 1;
    };
    auto fr = [](int x){
        if(x > 0)return -x + 1;
        return -(x + 1);
    };
    for(int i = 0; i < b.size(); ){
        if(last == b[i] and b[i] == 2){
            last = S;
            ++ i;
        }
        last = b[i];
        if(b[i] == 1 || b[i] == -1){
            while(i + 1 < b.size() && b[i + 1] == nxt(b[i]))
                ++ i;
            ++ i;
        }
        else{
            while(i + 1 < b.size() && b[i + 1] == fr(b[i]))
                ++ i;
            if(b[i] != 1 and b[i] != -1){
                cout << "No\n";
                return;
            }
            ++ i;
        }
    }
    cout << "Yes\n";
}

signed main() {
    // IOS
    int T = read();
    while (T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

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

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: 3492kb

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: 11ms
memory: 3560kb

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

result:

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