답안 #940616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940616 2024-03-07T11:43:24 Z groshi Wild Boar (JOI18_wild_boar) C++17
12 / 100
6 ms 45404 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int mam[100100];
struct wi{
    vector<int> Q;
    int dp[100100][2][2];///koszt, od kogo
}*w;
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,m,t,l,x,y,z;
    cin>>n>>m>>t>>l;
    w=new wi[n+3];
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y>>z;
        w[x].Q.push_back(y);
        w[x].Q.push_back(z);
        w[y].Q.push_back(x);
        w[y].Q.push_back(z);
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<=l;j++)
            w[i].dp[j][0][0]=1e18,w[i].dp[j][0][1]=1e18;
    for(int i=1;i<=l;i++)
        cin>>mam[i];
    cin>>x>>y;
    mam[x]=y;
    priority_queue<pair<pair<int,int>,pair<int,int> > > kolejka;
    kolejka.push({{0,mam[1]},{0,0}});
    w[mam[1]].dp[1][0][0]=0;
    while(!kolejka.empty())
    {
        auto para=kolejka.top();
        kolejka.pop();
        int x=para.first.second;
        int koszt=-para.first.first;
        int gdzie=para.second.first;
        int skad=para.second.second;
        if(mam[gdzie+1]==x)
            gdzie++;
        if((w[x].dp[gdzie][0][0]!=koszt || w[x].dp[gdzie][1][0]!=skad) && (w[x].dp[gdzie][0][1]!=koszt || w[x].dp[gdzie][1][1]!=skad))
            continue;
        for(int i=0;i<w[x].Q.size();i+=2)
        {
            int pom=w[x].Q[i];
            int ile=w[x].Q[i+1];
            if(pom==skad)
                continue;
            if(mam[gdzie+1]==pom)
                gdzie++;
            if(w[pom].dp[gdzie][0][1]<=koszt+ile)
            {
                if(mam[gdzie]==pom)
                    gdzie--;
                continue;
            }
            if(w[pom].dp[gdzie][0][0]>koszt+ile)
            {
                if(x!=w[pom].dp[gdzie][1][0] && x!=w[pom].dp[gdzie][1][1]){
                    w[pom].dp[gdzie][0][1]=w[pom].dp[gdzie][0][0];
                    w[pom].dp[gdzie][1][1]=w[pom].dp[gdzie][1][0];
                    w[pom].dp[gdzie][0][0]=koszt+ile;
                    w[pom].dp[gdzie][1][0]=x;
                }
                else if(x==w[pom].dp[gdzie][1][0])
                    w[pom].dp[gdzie][0][0]=koszt+ile;
                else w[pom].dp[gdzie][0][1]=koszt+ile;
                if(w[pom].dp[gdzie][0][1]<w[pom].dp[gdzie][0][0])
                    swap(w[pom].dp[gdzie][0][1],w[pom].dp[gdzie][0][0]),swap(w[pom].dp[gdzie][1][1],w[pom].dp[gdzie][1][0]);
            }
            else if(w[pom].dp[gdzie][0][1]>koszt+ile)
            {
                if(x==w[pom].dp[gdzie][1][0])
                {
                    if(mam[gdzie]==pom)
                        gdzie--;
                    continue;
                }
                w[pom].dp[gdzie][0][1]=koszt+ile;
                w[pom].dp[gdzie][1][1]=x;
            }
            if(mam[gdzie]==pom)
                gdzie--;
            kolejka.push({{-koszt-ile,pom},{gdzie,x}});
        }
    }
    if(w[mam[l]].dp[l][0][0]==1000000000000000000)
        cout<<"-1";
    else cout<<w[mam[l]].dp[l][0][0];
    return 0;
}

Compilation message

wild_boar.cpp: In function 'int32_t main()':
wild_boar.cpp:47:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i=0;i<w[x].Q.size();i+=2)
      |                     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 3 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 3 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 20828 KB Output is correct
12 Correct 3 ms 20824 KB Output is correct
13 Correct 3 ms 20828 KB Output is correct
14 Correct 3 ms 20828 KB Output is correct
15 Correct 3 ms 22876 KB Output is correct
16 Correct 3 ms 22872 KB Output is correct
17 Correct 3 ms 22876 KB Output is correct
18 Correct 3 ms 22876 KB Output is correct
19 Correct 3 ms 24924 KB Output is correct
20 Correct 3 ms 25080 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14684 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 3 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 3 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 20828 KB Output is correct
12 Correct 3 ms 20824 KB Output is correct
13 Correct 3 ms 20828 KB Output is correct
14 Correct 3 ms 20828 KB Output is correct
15 Correct 3 ms 22876 KB Output is correct
16 Correct 3 ms 22872 KB Output is correct
17 Correct 3 ms 22876 KB Output is correct
18 Correct 3 ms 22876 KB Output is correct
19 Correct 3 ms 24924 KB Output is correct
20 Correct 3 ms 25080 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14684 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Incorrect 6 ms 45404 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 3 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 3 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 20828 KB Output is correct
12 Correct 3 ms 20824 KB Output is correct
13 Correct 3 ms 20828 KB Output is correct
14 Correct 3 ms 20828 KB Output is correct
15 Correct 3 ms 22876 KB Output is correct
16 Correct 3 ms 22872 KB Output is correct
17 Correct 3 ms 22876 KB Output is correct
18 Correct 3 ms 22876 KB Output is correct
19 Correct 3 ms 24924 KB Output is correct
20 Correct 3 ms 25080 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14684 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Incorrect 6 ms 45404 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 3 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 3 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 20828 KB Output is correct
12 Correct 3 ms 20824 KB Output is correct
13 Correct 3 ms 20828 KB Output is correct
14 Correct 3 ms 20828 KB Output is correct
15 Correct 3 ms 22876 KB Output is correct
16 Correct 3 ms 22872 KB Output is correct
17 Correct 3 ms 22876 KB Output is correct
18 Correct 3 ms 22876 KB Output is correct
19 Correct 3 ms 24924 KB Output is correct
20 Correct 3 ms 25080 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14684 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Incorrect 6 ms 45404 KB Output isn't correct
27 Halted 0 ms 0 KB -