QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729369#7866. TeleportationLuCiiiDWA 1ms4164kbC++231.0kb2024-11-09 16:59:562024-11-09 16:59:58

Judging History

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

  • [2024-11-09 16:59:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4164kb
  • [2024-11-09 16:59:56]
  • 提交

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};
    queue<pair<int, int>> que;
    que.push({1, a[0]});
    while (que.size())
    {
        int nowstep = que.front().first, now = que.front().second;
        que.pop();
        if (!vis[(now + 1) % N])
        {
            vis[(now + 1) % N] = 1, que.push({nowstep + 1, (now + 1) % N});
            if ((now + 1) % N == X)
                return nowstep + 1;
        }
        if (!vis[(now + a[now]) % N])
        {
            vis[(now + a[now]) % N], que.push({nowstep + 1, (now + a[now]) % N});
            if ((now + a[now]) % N == X)
                return nowstep + 1;
        }
    }
    return inf;
}
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: 0ms
memory: 4000kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4164kb

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3928kb

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 4004kb

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3936kb

input:

2 1
1 1

output:

3

result:

wrong answer 1st numbers differ - expected: '1', found: '3'