QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369080 | #6506. Chase Game 3 | bigJ | WA | 1ms | 3780kb | C++20 | 1004b | 2024-03-27 20:20:33 | 2024-03-27 20:20:33 |
Judging History
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]