QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#781468#7866. TeleportationcyanacWA 1ms5432kbC++201.2kb2024-11-25 16:12:052024-11-25 16:12:25

Judging History

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

  • [2024-11-25 16:12:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5432kb
  • [2024-11-25 16:12:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
#define PII pair<int,int>
const int N=2e5+10;
struct node
{
    int to,w;
};
vector<node> h[N];
int dis[N];
bool st[N];
void add(int a,int b,int c)
{
    h[a].push_back({b,c});
}
int n,ed;
void dijkstra()
{
    memset(dis,0x3f,sizeof dis);
    priority_queue<PII,vector<PII>,greater<PII>> q;
    dis[n]=0;
    q.push({0,n});
    while(q.size())
    {
        //cout<<"aaa"<<endl;
        auto t=q.top();
        q.pop();
        if(st[t.y]) continue;
        st[t.y]=true;
       // cout<<t.y<<endl;
        for(int i=0;i<h[t.y].size();i++)
        {
            int j=h[t.y][i].to;
            if(dis[j]>dis[t.y]+h[t.y][i].w)
            {
               // if(j==3) cout<<t.y<<"aa"<<h[t.y][i].w<<endl;
                dis[j]=dis[t.y]+h[t.y][i].w;
                q.push({dis[j],j});
            }
        }

    }
}
signed main()
{
    //int n,ed;
    cin>>n>>ed;
    for(int i=0;i<n-1;i++)
    {
        add(i,i+1,1);
    }
    add(n-1,0,1);
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
       add(n+i,x,1);
       add(i,n+i,1);

        
    }
    dijkstra();
    cout<<dis[ed]<<endl;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5332kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

2 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

300 25
182 9 13 211 258 132 27 42 218 200 271 258 164 121 8 84 29 195 141 290 110 0 272 93 142 134 140 32 232 99 162 199 297 287 212 29 182 53 61 98 116 282 75 245 230 165 22 4 179 89 274 231 46 299 248 208 200 285 221 50 221 199 294 241 195 138 22 204 113 100 132 276 158 146 238 178 100 94 131 157 ...

output:

8

result:

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