Submission #58213

# Submission time Handle Problem Language Result Execution time Memory
58213 2018-07-17T07:42:40 Z 정원준(#1691) Wild Boar (JOI18_wild_boar) C++11
47 / 100
18000 ms 311152 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]].size();j++)
		{
			dp[i].push_back(inf);
		}
		if(i==1)
		{
			for(j=0;j<v[plan[i]].size();j++)
			{
				dp[i][j]=0;
			}
		}
		else
		{
			for(j=0;j<v[plan[i]].size();j++)
			{
				for(k=0;k<v[plan[i-1]].size();k++)
				{
					dp[i][j]=min(dp[i][j],dp[i-1][k]+dist[st[plan[i-1]]+k][st[plan[i]]+j]);
				}
			}
		}
		/*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

wild_boar.cpp: In function 'int main()':
wild_boar.cpp:76:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<v[i].size();j++)
           ~^~~~~~~~~~~~
wild_boar.cpp:78:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(k=0;k<v[v[i][j]].size();k++)
            ~^~~~~~~~~~~~~~~~~~
wild_boar.cpp:103:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(j=0;j<realv[x].size();j++)
            ~^~~~~~~~~~~~~~~~
wild_boar.cpp:123:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<v[plan[i]].size();j++)
           ~^~~~~~~~~~~~~~~~~~
wild_boar.cpp:129:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(j=0;j<v[plan[i]].size();j++)
            ~^~~~~~~~~~~~~~~~~~
wild_boar.cpp:136:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(j=0;j<v[plan[i]].size();j++)
            ~^~~~~~~~~~~~~~~~~~
wild_boar.cpp:138:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(k=0;k<v[plan[i-1]].size();k++)
             ~^~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:150:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<v[plan[l]].size();i++)
          ~^~~~~~~~~~~~~~~~~~
wild_boar.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld %lld",&n,&m,&t,&l);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&s[i],&e[i],&d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&plan[i]);
   ~~~~~^~~~~~~~~~~~~~~~~
wild_boar.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&xtemp,&ytemp);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3064 KB Output is correct
2 Correct 5 ms 3176 KB Output is correct
3 Correct 5 ms 3212 KB Output is correct
4 Correct 5 ms 3292 KB Output is correct
5 Correct 5 ms 3296 KB Output is correct
6 Correct 5 ms 3376 KB Output is correct
7 Correct 7 ms 3380 KB Output is correct
8 Correct 6 ms 3512 KB Output is correct
9 Correct 6 ms 3512 KB Output is correct
10 Correct 5 ms 3512 KB Output is correct
11 Correct 6 ms 3512 KB Output is correct
12 Correct 4 ms 3512 KB Output is correct
13 Correct 5 ms 3512 KB Output is correct
14 Correct 5 ms 3512 KB Output is correct
15 Correct 6 ms 3512 KB Output is correct
16 Correct 7 ms 3512 KB Output is correct
17 Correct 5 ms 3512 KB Output is correct
18 Correct 6 ms 3512 KB Output is correct
19 Correct 6 ms 3576 KB Output is correct
20 Correct 6 ms 3576 KB Output is correct
21 Correct 6 ms 3576 KB Output is correct
22 Correct 6 ms 3576 KB Output is correct
23 Correct 5 ms 3576 KB Output is correct
24 Correct 5 ms 3576 KB Output is correct
25 Correct 5 ms 3576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3064 KB Output is correct
2 Correct 5 ms 3176 KB Output is correct
3 Correct 5 ms 3212 KB Output is correct
4 Correct 5 ms 3292 KB Output is correct
5 Correct 5 ms 3296 KB Output is correct
6 Correct 5 ms 3376 KB Output is correct
7 Correct 7 ms 3380 KB Output is correct
8 Correct 6 ms 3512 KB Output is correct
9 Correct 6 ms 3512 KB Output is correct
10 Correct 5 ms 3512 KB Output is correct
11 Correct 6 ms 3512 KB Output is correct
12 Correct 4 ms 3512 KB Output is correct
13 Correct 5 ms 3512 KB Output is correct
14 Correct 5 ms 3512 KB Output is correct
15 Correct 6 ms 3512 KB Output is correct
16 Correct 7 ms 3512 KB Output is correct
17 Correct 5 ms 3512 KB Output is correct
18 Correct 6 ms 3512 KB Output is correct
19 Correct 6 ms 3576 KB Output is correct
20 Correct 6 ms 3576 KB Output is correct
21 Correct 6 ms 3576 KB Output is correct
22 Correct 6 ms 3576 KB Output is correct
23 Correct 5 ms 3576 KB Output is correct
24 Correct 5 ms 3576 KB Output is correct
25 Correct 5 ms 3576 KB Output is correct
26 Correct 6 ms 4040 KB Output is correct
27 Correct 40 ms 9928 KB Output is correct
28 Correct 42 ms 9928 KB Output is correct
29 Correct 188 ms 22336 KB Output is correct
30 Correct 426 ms 40236 KB Output is correct
31 Correct 2009 ms 100188 KB Output is correct
32 Correct 2151 ms 116896 KB Output is correct
33 Correct 113 ms 116896 KB Output is correct
34 Correct 111 ms 116896 KB Output is correct
35 Correct 2267 ms 117048 KB Output is correct
36 Correct 1371 ms 117048 KB Output is correct
37 Correct 175 ms 117048 KB Output is correct
38 Correct 143 ms 117048 KB Output is correct
39 Correct 730 ms 117048 KB Output is correct
40 Correct 97 ms 117048 KB Output is correct
41 Correct 96 ms 117048 KB Output is correct
42 Correct 679 ms 117048 KB Output is correct
43 Correct 88 ms 117048 KB Output is correct
44 Correct 84 ms 117048 KB Output is correct
45 Correct 55 ms 117048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3064 KB Output is correct
2 Correct 5 ms 3176 KB Output is correct
3 Correct 5 ms 3212 KB Output is correct
4 Correct 5 ms 3292 KB Output is correct
5 Correct 5 ms 3296 KB Output is correct
6 Correct 5 ms 3376 KB Output is correct
7 Correct 7 ms 3380 KB Output is correct
8 Correct 6 ms 3512 KB Output is correct
9 Correct 6 ms 3512 KB Output is correct
10 Correct 5 ms 3512 KB Output is correct
11 Correct 6 ms 3512 KB Output is correct
12 Correct 4 ms 3512 KB Output is correct
13 Correct 5 ms 3512 KB Output is correct
14 Correct 5 ms 3512 KB Output is correct
15 Correct 6 ms 3512 KB Output is correct
16 Correct 7 ms 3512 KB Output is correct
17 Correct 5 ms 3512 KB Output is correct
18 Correct 6 ms 3512 KB Output is correct
19 Correct 6 ms 3576 KB Output is correct
20 Correct 6 ms 3576 KB Output is correct
21 Correct 6 ms 3576 KB Output is correct
22 Correct 6 ms 3576 KB Output is correct
23 Correct 5 ms 3576 KB Output is correct
24 Correct 5 ms 3576 KB Output is correct
25 Correct 5 ms 3576 KB Output is correct
26 Correct 6 ms 4040 KB Output is correct
27 Correct 40 ms 9928 KB Output is correct
28 Correct 42 ms 9928 KB Output is correct
29 Correct 188 ms 22336 KB Output is correct
30 Correct 426 ms 40236 KB Output is correct
31 Correct 2009 ms 100188 KB Output is correct
32 Correct 2151 ms 116896 KB Output is correct
33 Correct 113 ms 116896 KB Output is correct
34 Correct 111 ms 116896 KB Output is correct
35 Correct 2267 ms 117048 KB Output is correct
36 Correct 1371 ms 117048 KB Output is correct
37 Correct 175 ms 117048 KB Output is correct
38 Correct 143 ms 117048 KB Output is correct
39 Correct 730 ms 117048 KB Output is correct
40 Correct 97 ms 117048 KB Output is correct
41 Correct 96 ms 117048 KB Output is correct
42 Correct 679 ms 117048 KB Output is correct
43 Correct 88 ms 117048 KB Output is correct
44 Correct 84 ms 117048 KB Output is correct
45 Correct 55 ms 117048 KB Output is correct
46 Correct 239 ms 117048 KB Output is correct
47 Execution timed out 18065 ms 311152 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3064 KB Output is correct
2 Correct 5 ms 3176 KB Output is correct
3 Correct 5 ms 3212 KB Output is correct
4 Correct 5 ms 3292 KB Output is correct
5 Correct 5 ms 3296 KB Output is correct
6 Correct 5 ms 3376 KB Output is correct
7 Correct 7 ms 3380 KB Output is correct
8 Correct 6 ms 3512 KB Output is correct
9 Correct 6 ms 3512 KB Output is correct
10 Correct 5 ms 3512 KB Output is correct
11 Correct 6 ms 3512 KB Output is correct
12 Correct 4 ms 3512 KB Output is correct
13 Correct 5 ms 3512 KB Output is correct
14 Correct 5 ms 3512 KB Output is correct
15 Correct 6 ms 3512 KB Output is correct
16 Correct 7 ms 3512 KB Output is correct
17 Correct 5 ms 3512 KB Output is correct
18 Correct 6 ms 3512 KB Output is correct
19 Correct 6 ms 3576 KB Output is correct
20 Correct 6 ms 3576 KB Output is correct
21 Correct 6 ms 3576 KB Output is correct
22 Correct 6 ms 3576 KB Output is correct
23 Correct 5 ms 3576 KB Output is correct
24 Correct 5 ms 3576 KB Output is correct
25 Correct 5 ms 3576 KB Output is correct
26 Correct 6 ms 4040 KB Output is correct
27 Correct 40 ms 9928 KB Output is correct
28 Correct 42 ms 9928 KB Output is correct
29 Correct 188 ms 22336 KB Output is correct
30 Correct 426 ms 40236 KB Output is correct
31 Correct 2009 ms 100188 KB Output is correct
32 Correct 2151 ms 116896 KB Output is correct
33 Correct 113 ms 116896 KB Output is correct
34 Correct 111 ms 116896 KB Output is correct
35 Correct 2267 ms 117048 KB Output is correct
36 Correct 1371 ms 117048 KB Output is correct
37 Correct 175 ms 117048 KB Output is correct
38 Correct 143 ms 117048 KB Output is correct
39 Correct 730 ms 117048 KB Output is correct
40 Correct 97 ms 117048 KB Output is correct
41 Correct 96 ms 117048 KB Output is correct
42 Correct 679 ms 117048 KB Output is correct
43 Correct 88 ms 117048 KB Output is correct
44 Correct 84 ms 117048 KB Output is correct
45 Correct 55 ms 117048 KB Output is correct
46 Correct 239 ms 117048 KB Output is correct
47 Execution timed out 18065 ms 311152 KB Time limit exceeded
48 Halted 0 ms 0 KB -