QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604977#7866. Teleportationucup-team4906#WA 0ms3812kbC++201.1kb2024-10-02 14:52:242024-10-02 14:52:25

Judging History

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

  • [2024-10-02 14:52:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-10-02 14:52:24]
  • 提交

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;
    }

    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;
        auto calc = [&](int x)
        {
            if (dis[u] + 1 < dis[x])
            {
                dis[x] = dis[u] + 1;
                q.push({dis[x], x});
            }
        };

        calc(a[u]);
        calc(u + 1);
    }
    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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3528kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3540kb

input:

2 1
1 1

output:

3

result:

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