Submission #584312

# Submission time Handle Problem Language Result Execution time Memory
584312 2022-06-27T08:00:31 Z 조영욱(#8377) Wild Boar (JOI18_wild_boar) C++17
12 / 100
18000 ms 2812 KB
#include <bits/stdc++.h>
using namespace std;

int n,m,t,l;
typedef pair<long long,int> P;
vector<P> adj[4001];
int arr[100001];
long long dp[100001];
long long dp0[100001];
int pos[100001];
bool vis[4001];
long long dist[4001];
const long long INF=1e18;

void dijk(int st,int en,int a,int b,int c,int d) {
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push(P(0,st));
    for(int i=1;i<=n*2;i++) {
        vis[i]=false;
        dist[i]=INF;
    }
    dist[st]=0;
    while (!pq.empty()) {
        P now=pq.top();
        pq.pop();
        if (vis[now.second]) {
            continue;
        }
        vis[now.second]=true;
        for(int i=0;i<adj[now.second].size();i++) {
            int nt=adj[now.second][i].first;
            if (now.second==a&&nt==b) {
                continue;
            }
            if (nt==a&&now.second==b) {
                continue;
            }
            if (now.second==c&&nt==d) {
                continue;
            }
            if (nt==c&&now.second==d) {
                continue;
            }
            if (dist[nt]>dist[now.second]+adj[now.second][i].second) {
                dist[nt]=dist[now.second]+adj[now.second][i].second;
                pq.push(P(dist[nt],nt));
            }
        }
    }
}

int main(void) {
    scanf("%d %d %d %d",&n,&m,&t,&l);
    for(int i=0;i<m;i++) {
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        adj[u].push_back(P(v,w));
        adj[v].push_back(P(u,w));
    }
    for(int i=1;i<=l;i++) {
        scanf("%d",&arr[i]);
    }
    int p,q;
    scanf("%d %d",&p,&q);
    arr[p]=q;
    dp[1]=0;
    dp0[1]=0;
    pos[1]=arr[0];
    for(int i=2;i<=l;i++) {
        int now=arr[i];
        vector<long long> vec(adj[now].size());
        for(int j=0;j<adj[now].size();j++) {
            int nt=adj[now][j].first;
            dijk(arr[i-1],arr[i],now,nt,0,0);
            vec[j]=dist[nt]+adj[now][j].second+dp0[i-1];
        }
        for(int j=0;j<adj[now].size();j++) {
            int nt=adj[now][j].first;
if (nt==arr[i-1]&&now==pos[i-1]) continue;
        dijk(arr[i-1],arr[i],now,nt,arr[i-1],pos[i-1]);
            vec[j]=min(vec[j],dist[nt]+adj[now][j].second+dp[i-1]);
        }
        long long mn=INF;
        int ind=now;
        for(int j=0;j<adj[now].size();j++) {
            int nt=adj[now][j].first;
            if (vec[j]<mn) {
                ind=nt;
                mn=vec[j];
            }
        }
        long long mn2=INF;
        for(int j=0;j<adj[now].size();j++) {
            if (adj[now][j].first!=ind) {
                mn2=min(mn2,vec[j]);
            }
        }
        dp[i]=mn;
        dp0[i]=mn2;
        pos[i]=ind;
//printf("%lld %lld %d\n",mn,mn2,ind);
    }
    printf("%lld",dp[l]>=INF?-1:dp[l]);
}

Compilation message

wild_boar.cpp: In function 'void dijk(int, int, int, int, int, int)':
wild_boar.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i=0;i<adj[now.second].size();i++) {
      |                     ~^~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp: In function 'int main()':
wild_boar.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for(int j=0;j<adj[now].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
wild_boar.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(int j=0;j<adj[now].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
wild_boar.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int j=0;j<adj[now].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
wild_boar.cpp:93:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         for(int j=0;j<adj[now].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
wild_boar.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     scanf("%d %d %d %d",&n,&m,&t,&l);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%d %d %d",&u,&v,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
wild_boar.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d %d",&p,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 1936 ms 2648 KB Output is correct
28 Correct 1869 ms 2812 KB Output is correct
29 Correct 17341 ms 2744 KB Output is correct
30 Execution timed out 18044 ms 1308 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 1936 ms 2648 KB Output is correct
28 Correct 1869 ms 2812 KB Output is correct
29 Correct 17341 ms 2744 KB Output is correct
30 Execution timed out 18044 ms 1308 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 1936 ms 2648 KB Output is correct
28 Correct 1869 ms 2812 KB Output is correct
29 Correct 17341 ms 2744 KB Output is correct
30 Execution timed out 18044 ms 1308 KB Time limit exceeded
31 Halted 0 ms 0 KB -