QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605016 | #7866. Teleportation | ucup-team4906# | WA | 1ms | 3860kb | C++20 | 1.1kb | 2024-10-02 15:02:48 | 2024-10-02 15:02:48 |
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;
}
dis[0] = 0;
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;
vis[u] = 1;
auto calc = [&](int x)
{
if (dis[u] + 1 < dis[x])
{
dis[x] = dis[u] + 1;
q.push({dis[x], x});
}
};
calc((u + a[u]) % n);
calc((u + 1) % n);
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3848kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
4 3 0 0 0 0
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 3 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
2 1 0 0
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
2 1 1 1
output:
3
result:
wrong answer 1st numbers differ - expected: '1', found: '3'