QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#600603#6306. Chase Gameucup-team3691#WA 2ms9788kbC++202.2kb2024-09-29 17:37:212024-09-29 17:37:25

Judging History

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

  • [2024-09-29 17:37:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9788kb
  • [2024-09-29 17:37:21]
  • 提交

answer

#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
long long inf=1e16;
long long dist[200005];
long long dist2[200005];
long long dist3[200005];
long long lung[200005];
vector<long long>adj[200005];
queue<long long>qu;
priority_queue<pair<long long,long long> >pq;
int main()
{
    long long n,i,j,k,l,op,t,a,b,sum=0,m,st,r;
    cin>>n>>m>>st>>r;
    for(i=1;i<=m;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(i=1;i<=n;i++)
    {
        dist[i]=0;
    }
    dist[st]=r;
    qu.push(st);
    while(qu.size())
    {
        long long curr=qu.front();
        qu.pop();
        for(auto k:adj[curr])
        {
            if(dist[k]<dist[curr]-1)
            {
                dist[k]=dist[curr]-1;
                qu.push(k);
            }
        }
    }/*
    for(i=1;i<=n;i++)
    {
        cout<<dist[i];
    }*/
    for(i=1;i<=n;i++)
    {
        dist2[i]=inf;
    }
    dist2[1]=0;
    pq.push({0,1});
    while(pq.size())
    {
        long long curr=pq.top().second;
        long long val=pq.top().first;
        pq.pop();
        if(val==-dist2[curr] && (dist[curr]>=1 || curr==1))
        {
            for(auto k:adj[curr])
            {
                if(dist2[curr]+dist[k]<dist2[k])
                {
                    dist2[k]=dist2[curr]+dist[k];
                    pq.push({-dist2[k],k});
                }
            }
        }
    }
    long long val=r;
    for(i=1;i<=n;i++)
    {
        lung[i]=lung[i-1]+val;
        val--;
        if(val==0)
        {
            val=r;
        }
    }
    for(i=1;i<=n;i++)
    {
        dist3[i]=inf;
    }
    dist3[n]=0;
    qu.push(n);
    while(qu.size())
    {
        long long curr=qu.front();
        qu.pop();
        for(auto k:adj[curr])
        {
            if(dist3[k]>dist3[curr]+1)
            {
                dist3[k]=dist3[curr]+1;
                qu.push(k);
            }
        }
    }
    long long sol=inf;
    for(i=2;i<=n;i++)
    {
        if(dist[i]==0)
        {
            sol=min(sol,dist2[i]+lung[dist3[i]+1]);
        }
    }
    cout<<sol;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7876kb

input:

5 5 3 1
1 2
2 4
4 5
1 3
3 5

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

13 17 12 3
1 2
2 3
3 4
4 13
5 13
7 8
7 9
7 10
7 11
7 6
12 7
1 8
8 9
9 10
10 11
11 6
6 13

output:

7

result:

ok 1 number(s): "7"

Test #3:

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

input:

10 9 4 1
4 3
1 2
7 6
6 5
8 9
9 10
5 4
8 7
3 2

output:

9

result:

ok 1 number(s): "9"

Test #4:

score: 0
Accepted
time: 2ms
memory: 9788kb

input:

10 20 9 1
9 5
2 9
4 5
10 5
7 3
1 8
7 1
7 5
3 4
3 1
7 8
3 8
9 3
10 6
9 1
1 6
8 5
6 2
1 10
2 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

10 20 3 1
1 4
6 7
5 4
5 3
2 1
8 1
7 8
2 6
2 4
4 8
9 5
1 10
7 4
5 8
4 10
2 5
6 10
4 6
3 7
1 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

10 20 4 1
2 7
6 4
2 3
2 4
6 5
8 5
6 7
10 2
3 10
1 8
3 9
3 7
1 7
5 1
6 1
3 4
2 1
5 2
9 2
9 10

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

10 20 1 10
10 9
2 5
7 8
7 10
10 8
8 9
5 6
3 1
6 4
7 9
2 3
3 6
2 1
8 6
5 8
7 4
4 3
2 4
4 1
9 6

output:

10000000000000000

result:

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