QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#727817 | #7866. Teleportation | LuCiiiD | WA | 1ms | 4360kb | C++23 | 1.0kb | 2024-11-09 13:54:18 | 2024-11-09 13:54:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define _11037_ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define endl '\n'
#define inf 2e9
#define MAX 100005
#define MOD 998244353
int N, X, a[MAX];
int BFS(int start)
{
int vis[MAX] = {0}, dis[MAX];
for (int i = 0; i < MAX; i++)
dis[i] = inf;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
que.push({0, 0}), dis[0] = 0, vis[0] = 1;
while (que.size())
{
int nowstep = que.top().first, now = que.top().second;
if (now == X)
return dis[X];
que.pop();
if (vis[(now + a[now] + 1) % N])
continue;
vis[(now + a[now] + 1) % N] = 1;
dis[(now + a[now] + 1) % N] = min(dis[(now + a[now] + 1) % N], nowstep + 1 + 1);
que.push({dis[(now + a[now] + 1) % N], (now + a[now] + 1) % N});
}
return dis[X];
}
signed main()
{
_11037_
cin >> N >> X;
for (int i = 0; i < N; i++)
cin >> a[i];
cout << BFS(0) << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4332kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4360kb
input:
4 3 0 0 0 0
output:
6
result:
wrong answer 1st numbers differ - expected: '4', found: '6'