QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#369080#6506. Chase Game 3bigJWA 1ms3780kbC++201004b2024-03-27 20:20:332024-03-27 20:20:33

Judging History

This is the latest submission verdict.

  • [2024-03-27 20:20:33]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3780kb
  • [2024-03-27 20:20:33]
  • Submitted

answer

#include <bits/stdc++.h>

using i64 = int64_t;

namespace stdr = std::ranges;
namespace stdv = std::views;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> p(n), nxt(n, -1);

    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
        p[i]--;
    }

    for (int i = 0; i + 1 < n; i++) {
        if (p[i + 1] != p[i] + 1) {
            nxt[p[i]] = p[i + 1];
        }
    }

    std::vector<bool> vis(n);
    for (int i = 0; i < n; i++) {
        if (vis[i]) {
            continue;
        }
        int cnt = 1;
        while (i != -1 && !vis[i]) {
            vis[i] = true;
            i = nxt[i];
            cnt++;
        }
        if (cnt >= 4) {
            std::cout << "No\n";
            return;
        }
    }

    std::cout << "Yes\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3780kb

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: -100
Wrong Answer
time: 1ms
memory: 3520kb

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
No

result:

wrong answer expected YES, found NO [8th token]