QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#604977 | #7866. Teleportation | ucup-team4906# | WA | 0ms | 3812kb | C++20 | 1.1kb | 2024-10-02 14:52:24 | 2024-10-02 14:52:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
void solve()
{
int n, t;
cin >> n >> t;
vi a(n + 2);
for (int i = 0; i < n; i++)
cin >> a[i];
vi dis(n + 2), vis(n + 2);
for (int i = 0; i < n; i++)
{
int x = i, y = a[0];
if (y < x) dis[i] = x - y + 1;
else dis[i] = n - y + x + 1;
}
priority_queue<array<int, 2>, vector<array<int, 2>>, greater<array<int, 2>>> q;
for (int i = 1; i < n; i++)
q.push({dis[i], i});
while (!q.empty())
{
auto [_, u] = q.top();
q.pop();
if (vis[u]) continue;
auto calc = [&](int x)
{
if (dis[u] + 1 < dis[x])
{
dis[x] = dis[u] + 1;
q.push({dis[x], x});
}
};
calc(a[u]);
calc(u + 1);
}
cout << dis[t] << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
4 3 0 0 0 0
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
4 3 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2 1 0 0
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3540kb
input:
2 1 1 1
output:
3
result:
wrong answer 1st numbers differ - expected: '1', found: '3'