QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749822 | #7866. Teleportation | 4eyebird# | RE | 0ms | 3940kb | C++17 | 1.2kb | 2024-11-15 10:35:09 | 2024-11-15 10:35:10 |
Judging History
answer
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
constexpr int inf = 0x3f3f3f3f;
#define Buff ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
//#define int long long
constexpr int N = 100010;
int n, qx;
int a[N],dis[N];
void solve()
{
cin >> n >> qx;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
queue<int> q;
dis[a[0]] = 1;
q.push(a[0]);
while (!q.empty())
{
auto u = q.front();
q.pop();
int v = u + 1;
if (!dis[v])
{
q.push(v);
dis[v] = dis[u] + 1;
}
v = (u + a[u]) % n;
if (!dis[v])
{
q.push(v);
dis[v] = dis[u] + 1;
}
}
cout << dis[qx];
}
signed main()
{
#ifdef YGYYYGJ
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
Buff;
int _T_ = 1;
while (_T_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3940kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Runtime Error
input:
4 3 0 0 0 0