QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#756435 | #7866. Teleportation | Asda111 | WA | 0ms | 11920kb | C++17 | 1.8kb | 2024-11-16 20:28:35 | 2024-11-16 20:28:35 |
Judging History
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'