QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605016#7866. Teleportationucup-team4906#WA 1ms3860kbC++201.1kb2024-10-02 15:02:482024-10-02 15:02:48

Judging History

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

  • [2024-10-02 15:02:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3860kb
  • [2024-10-02 15:02:48]
  • 提交

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'