# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
58215 | 2018-07-17T08:01:22 Z | 정원준(#1691) | Wild Boar (JOI18_wild_boar) | C++11 | 18000 ms | 328708 KB |
#include <bits/stdc++.h> #define L long long using namespace std; const L inf=1e18; L n,m,t,l,ans=inf; L s[2020],e[2020],d[2020]; vector<L>v[2020],dis[2020]; L plan[100010]; L versum=1; L st[2020],ed[2020]; vector<L>realv[4040],realdis[4040]; L dist[4040][4040],chk[4040][4040]; vector<L>dp[100010]; struct S{ L loc,dist; }; bool operator<(S a,S b){ return a.dist>b.dist; } priority_queue<S>Q; int main() { scanf("%lld %lld %lld %lld",&n,&m,&t,&l); L i,j,k; for(i=1;i<=m;i++) { scanf("%lld %lld %lld",&s[i],&e[i],&d[i]); v[s[i]].push_back(e[i]); v[e[i]].push_back(s[i]); dis[s[i]].push_back(d[i]); dis[e[i]].push_back(d[i]); } for(i=1;i<=l;i++) { scanf("%lld",&plan[i]); } L xtemp,ytemp; scanf("%lld %lld",&xtemp,&ytemp); plan[xtemp]=ytemp; n++; v[plan[l]].push_back(n+1); v[n+1].push_back(plan[l]); dis[plan[l]].push_back(0); dis[n+1].push_back(0); for(i=1;i<=n;i++) { st[i]=versum; ed[i]=versum+v[i].size(); versum+=v[i].size(); } versum--; for(i=1;i<=versum;i++) { for(j=1;j<=versum;j++) { dist[i][j]=inf; } } L cnt=0; for(i=1;i<=n;i++) { for(j=0;j<v[i].size();j++) { for(k=0;k<v[v[i][j]].size();k++) { if(v[v[i][j]][k]!=i) { L ss=st[i]+j; L ee=st[v[i][j]]+k; //printf("%lld %lld %lld %lld\n",i,ss,v[i][j],ee); realv[ss].push_back(ee); realdis[ss].push_back(dis[i][j]); //printf("%lld %lld\n",i,v[i][j]); cnt++; } } } } //printf("%lld",cnt); for(i=1;i<=versum;i++) { dist[i][i]=0; Q.push((S){i,0}); while(!Q.empty()) { L x=Q.top().loc;Q.pop(); if(chk[i][x]) continue; chk[i][x]=1; for(j=0;j<realv[x].size();j++) { if(dist[i][realv[x][j]]>dist[i][x]+realdis[x][j]) { dist[i][realv[x][j]]=dist[i][x]+realdis[x][j]; Q.push((S){realv[x][j],dist[i][x]+realdis[x][j]}); } } } } /*for(i=1;i<=versum;i++) { for(j=1;j<=versum;j++) { printf("%lld ",dist[i][j]); } puts(""); }*/ for(i=1;i<l;i++) { for(j=0;j<v[plan[i+1]].size();j++) { dp[i+1].push_back(inf); } if(i==1) { for(j=0;j<v[plan[i]].size();j++) { dp[i].push_back(inf); } for(j=0;j<v[plan[i]].size();j++) { dp[i][j]=0; } } for(j=0;j<v[plan[i]].size();j++) { if(dp[i][j]!=inf) { for(k=0;k<v[plan[i+1]].size();k++) { dp[i+1][k]=min(dp[i+1][k],dp[i][j]+dist[st[plan[i]]+j][st[plan[i+1]]+k]); } } } /*for(j=0;j<v[plan[i]].size();j++) { printf("%lld ",dp[i][j]); } puts("");*/ } for(i=0;i<v[plan[l]].size();i++) { ans=min(ans,dp[l][i]); } printf("%lld",ans>=inf?-1:ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3300 KB | Output is correct |
3 | Correct | 6 ms | 3300 KB | Output is correct |
4 | Correct | 4 ms | 3392 KB | Output is correct |
5 | Correct | 4 ms | 3404 KB | Output is correct |
6 | Correct | 4 ms | 3404 KB | Output is correct |
7 | Correct | 6 ms | 3404 KB | Output is correct |
8 | Correct | 4 ms | 3404 KB | Output is correct |
9 | Correct | 4 ms | 3404 KB | Output is correct |
10 | Correct | 7 ms | 3404 KB | Output is correct |
11 | Correct | 6 ms | 3404 KB | Output is correct |
12 | Correct | 6 ms | 3404 KB | Output is correct |
13 | Correct | 4 ms | 3428 KB | Output is correct |
14 | Correct | 5 ms | 3428 KB | Output is correct |
15 | Correct | 5 ms | 3428 KB | Output is correct |
16 | Correct | 4 ms | 3428 KB | Output is correct |
17 | Correct | 5 ms | 3428 KB | Output is correct |
18 | Correct | 5 ms | 3428 KB | Output is correct |
19 | Correct | 5 ms | 3428 KB | Output is correct |
20 | Correct | 5 ms | 3428 KB | Output is correct |
21 | Correct | 4 ms | 3428 KB | Output is correct |
22 | Correct | 5 ms | 3432 KB | Output is correct |
23 | Correct | 4 ms | 3432 KB | Output is correct |
24 | Correct | 5 ms | 3432 KB | Output is correct |
25 | Correct | 5 ms | 3432 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3300 KB | Output is correct |
3 | Correct | 6 ms | 3300 KB | Output is correct |
4 | Correct | 4 ms | 3392 KB | Output is correct |
5 | Correct | 4 ms | 3404 KB | Output is correct |
6 | Correct | 4 ms | 3404 KB | Output is correct |
7 | Correct | 6 ms | 3404 KB | Output is correct |
8 | Correct | 4 ms | 3404 KB | Output is correct |
9 | Correct | 4 ms | 3404 KB | Output is correct |
10 | Correct | 7 ms | 3404 KB | Output is correct |
11 | Correct | 6 ms | 3404 KB | Output is correct |
12 | Correct | 6 ms | 3404 KB | Output is correct |
13 | Correct | 4 ms | 3428 KB | Output is correct |
14 | Correct | 5 ms | 3428 KB | Output is correct |
15 | Correct | 5 ms | 3428 KB | Output is correct |
16 | Correct | 4 ms | 3428 KB | Output is correct |
17 | Correct | 5 ms | 3428 KB | Output is correct |
18 | Correct | 5 ms | 3428 KB | Output is correct |
19 | Correct | 5 ms | 3428 KB | Output is correct |
20 | Correct | 5 ms | 3428 KB | Output is correct |
21 | Correct | 4 ms | 3428 KB | Output is correct |
22 | Correct | 5 ms | 3432 KB | Output is correct |
23 | Correct | 4 ms | 3432 KB | Output is correct |
24 | Correct | 5 ms | 3432 KB | Output is correct |
25 | Correct | 5 ms | 3432 KB | Output is correct |
26 | Correct | 6 ms | 3940 KB | Output is correct |
27 | Correct | 40 ms | 9956 KB | Output is correct |
28 | Correct | 41 ms | 10124 KB | Output is correct |
29 | Correct | 229 ms | 22536 KB | Output is correct |
30 | Correct | 371 ms | 40284 KB | Output is correct |
31 | Correct | 2124 ms | 100364 KB | Output is correct |
32 | Correct | 1963 ms | 117024 KB | Output is correct |
33 | Correct | 151 ms | 117024 KB | Output is correct |
34 | Correct | 122 ms | 117024 KB | Output is correct |
35 | Correct | 2770 ms | 117024 KB | Output is correct |
36 | Correct | 1302 ms | 117024 KB | Output is correct |
37 | Correct | 143 ms | 117024 KB | Output is correct |
38 | Correct | 108 ms | 117024 KB | Output is correct |
39 | Correct | 717 ms | 117024 KB | Output is correct |
40 | Correct | 154 ms | 117024 KB | Output is correct |
41 | Correct | 171 ms | 117024 KB | Output is correct |
42 | Correct | 895 ms | 117024 KB | Output is correct |
43 | Correct | 91 ms | 117024 KB | Output is correct |
44 | Correct | 86 ms | 117024 KB | Output is correct |
45 | Correct | 56 ms | 117024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3300 KB | Output is correct |
3 | Correct | 6 ms | 3300 KB | Output is correct |
4 | Correct | 4 ms | 3392 KB | Output is correct |
5 | Correct | 4 ms | 3404 KB | Output is correct |
6 | Correct | 4 ms | 3404 KB | Output is correct |
7 | Correct | 6 ms | 3404 KB | Output is correct |
8 | Correct | 4 ms | 3404 KB | Output is correct |
9 | Correct | 4 ms | 3404 KB | Output is correct |
10 | Correct | 7 ms | 3404 KB | Output is correct |
11 | Correct | 6 ms | 3404 KB | Output is correct |
12 | Correct | 6 ms | 3404 KB | Output is correct |
13 | Correct | 4 ms | 3428 KB | Output is correct |
14 | Correct | 5 ms | 3428 KB | Output is correct |
15 | Correct | 5 ms | 3428 KB | Output is correct |
16 | Correct | 4 ms | 3428 KB | Output is correct |
17 | Correct | 5 ms | 3428 KB | Output is correct |
18 | Correct | 5 ms | 3428 KB | Output is correct |
19 | Correct | 5 ms | 3428 KB | Output is correct |
20 | Correct | 5 ms | 3428 KB | Output is correct |
21 | Correct | 4 ms | 3428 KB | Output is correct |
22 | Correct | 5 ms | 3432 KB | Output is correct |
23 | Correct | 4 ms | 3432 KB | Output is correct |
24 | Correct | 5 ms | 3432 KB | Output is correct |
25 | Correct | 5 ms | 3432 KB | Output is correct |
26 | Correct | 6 ms | 3940 KB | Output is correct |
27 | Correct | 40 ms | 9956 KB | Output is correct |
28 | Correct | 41 ms | 10124 KB | Output is correct |
29 | Correct | 229 ms | 22536 KB | Output is correct |
30 | Correct | 371 ms | 40284 KB | Output is correct |
31 | Correct | 2124 ms | 100364 KB | Output is correct |
32 | Correct | 1963 ms | 117024 KB | Output is correct |
33 | Correct | 151 ms | 117024 KB | Output is correct |
34 | Correct | 122 ms | 117024 KB | Output is correct |
35 | Correct | 2770 ms | 117024 KB | Output is correct |
36 | Correct | 1302 ms | 117024 KB | Output is correct |
37 | Correct | 143 ms | 117024 KB | Output is correct |
38 | Correct | 108 ms | 117024 KB | Output is correct |
39 | Correct | 717 ms | 117024 KB | Output is correct |
40 | Correct | 154 ms | 117024 KB | Output is correct |
41 | Correct | 171 ms | 117024 KB | Output is correct |
42 | Correct | 895 ms | 117024 KB | Output is correct |
43 | Correct | 91 ms | 117024 KB | Output is correct |
44 | Correct | 86 ms | 117024 KB | Output is correct |
45 | Correct | 56 ms | 117024 KB | Output is correct |
46 | Correct | 236 ms | 117024 KB | Output is correct |
47 | Execution timed out | 18062 ms | 328708 KB | Time limit exceeded |
48 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3300 KB | Output is correct |
3 | Correct | 6 ms | 3300 KB | Output is correct |
4 | Correct | 4 ms | 3392 KB | Output is correct |
5 | Correct | 4 ms | 3404 KB | Output is correct |
6 | Correct | 4 ms | 3404 KB | Output is correct |
7 | Correct | 6 ms | 3404 KB | Output is correct |
8 | Correct | 4 ms | 3404 KB | Output is correct |
9 | Correct | 4 ms | 3404 KB | Output is correct |
10 | Correct | 7 ms | 3404 KB | Output is correct |
11 | Correct | 6 ms | 3404 KB | Output is correct |
12 | Correct | 6 ms | 3404 KB | Output is correct |
13 | Correct | 4 ms | 3428 KB | Output is correct |
14 | Correct | 5 ms | 3428 KB | Output is correct |
15 | Correct | 5 ms | 3428 KB | Output is correct |
16 | Correct | 4 ms | 3428 KB | Output is correct |
17 | Correct | 5 ms | 3428 KB | Output is correct |
18 | Correct | 5 ms | 3428 KB | Output is correct |
19 | Correct | 5 ms | 3428 KB | Output is correct |
20 | Correct | 5 ms | 3428 KB | Output is correct |
21 | Correct | 4 ms | 3428 KB | Output is correct |
22 | Correct | 5 ms | 3432 KB | Output is correct |
23 | Correct | 4 ms | 3432 KB | Output is correct |
24 | Correct | 5 ms | 3432 KB | Output is correct |
25 | Correct | 5 ms | 3432 KB | Output is correct |
26 | Correct | 6 ms | 3940 KB | Output is correct |
27 | Correct | 40 ms | 9956 KB | Output is correct |
28 | Correct | 41 ms | 10124 KB | Output is correct |
29 | Correct | 229 ms | 22536 KB | Output is correct |
30 | Correct | 371 ms | 40284 KB | Output is correct |
31 | Correct | 2124 ms | 100364 KB | Output is correct |
32 | Correct | 1963 ms | 117024 KB | Output is correct |
33 | Correct | 151 ms | 117024 KB | Output is correct |
34 | Correct | 122 ms | 117024 KB | Output is correct |
35 | Correct | 2770 ms | 117024 KB | Output is correct |
36 | Correct | 1302 ms | 117024 KB | Output is correct |
37 | Correct | 143 ms | 117024 KB | Output is correct |
38 | Correct | 108 ms | 117024 KB | Output is correct |
39 | Correct | 717 ms | 117024 KB | Output is correct |
40 | Correct | 154 ms | 117024 KB | Output is correct |
41 | Correct | 171 ms | 117024 KB | Output is correct |
42 | Correct | 895 ms | 117024 KB | Output is correct |
43 | Correct | 91 ms | 117024 KB | Output is correct |
44 | Correct | 86 ms | 117024 KB | Output is correct |
45 | Correct | 56 ms | 117024 KB | Output is correct |
46 | Correct | 236 ms | 117024 KB | Output is correct |
47 | Execution timed out | 18062 ms | 328708 KB | Time limit exceeded |
48 | Halted | 0 ms | 0 KB | - |