QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749822#7866. Teleportation4eyebird#RE 0ms3940kbC++171.2kb2024-11-15 10:35:092024-11-15 10:35:10

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 10:35:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3940kb
  • [2024-11-15 10:35:09]
  • 提交

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

output:


result: