QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#756435#7866. TeleportationAsda111WA 0ms11920kbC++171.8kb2024-11-16 20:28:352024-11-16 20:28:35

Judging History

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

  • [2024-11-16 20:28:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11920kb
  • [2024-11-16 20:28:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using PII = pair<int,int>;
const int N = 100005;
int n, m;
int a[N];
int h[N * 2], nxt[N * 5], to[N * 5], w[N * 5], cnt = 1;
void ad(int a, int b, int c)
{
    to[cnt] = b;
    nxt[cnt] = h[a];
    w[cnt] = c;
    h[a] = cnt++;
}

bool vis[N * 3];
int d[N * 3];


priority_queue< PII, vector<PII>, greater< PII >> q;

void dijkstra(int s)
{
    d[s] = 0;
    q.push({0, s});
    while (!q.empty())
    {
        int u = q.top().second;
        q.pop();
        if (vis[u])
            continue;
        vis[u] = 1;
        for (int i = h[u]; ~i; i = nxt[i])
        {
            int v = to[i], wd = w[i];
            if (d[v] > d[u] + wd)
            {
                d[v] = d[u] + wd;
                q.push({d[v], v});
            }
        }
    }
}

// int spfa(int s)
// {
//     d[s] = 0;
//     vis[s] = 1;
//     q.push(s);
//     while (!q.empty())
//     {
//         int x = q.front();
//         q.pop();
//         vis[x] = 0;
//         for (int i = h[x]; ~i; i = nxt[i])
//         {
//             int y = to[i];
//             int z = w[i];
//             if (d[y] > d[x] + z)
//             {
//                 d[y] = d[x] + z;
//                 if (!vis[y])
//                     q.push(y), vis[y] = 1;
//             }
//         }
//     }
//     return d[m];
// }

int main()
{
    memset(h, -1, sizeof(h));
    memset(d, 0x3f, sizeof(d));
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a + i);
    }
    for (int i = 0; i < n; i++)
    {
        ad(i + n, i, 0);
        //ad(i, i + n, i == 0);
        ad(i, (i + a[i]+n) % n, 1);
        ad(i + n, (i + 1) % n + n, 1);
    }
    dijkstra(0);
    cout << d[m];
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11920kb

input:

4 3
0 1 2 3

output:

1061109567

result:

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