답안 #83873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83873 2018-11-11T13:44:43 Z farukkastamonuda Soccer (JOI17_soccer) C++14
100 / 100
760 ms 30028 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define ii pair<lo int,lo int>
#define iii pair<lo int ,ii>
using namespace std;
typedef array<lo int,4> T;
lo int h,w,A,B,C,n,s[li],t[li],dist[505][505],dx[5]={0,-1,1,0},dy[5]={1,0,0,-1};
queue< iii > qq;
lo int dp[505][505][6];
priority_queue<T,vector<T>,greater<T>> q;
void tri(int p0,int p1,int z,lo int res){
	if(p0<0 || p1<0 || p0>h || p1>w) return ;
	if(dp[p0][p1][z]<=res) return ;
	q.push({dp[p0][p1][z]=res,p0,p1,z});
}
void bfs(){
	q.push({dp[s[1]][s[2]][4]=0,s[1],t[1],4});
	while(!q.empty()){
		auto a=q.top();
		q.pop();
		if(a[0]>dp[a[1]][a[2]][a[3]]) continue;
		if(a[3]<4){
			tri(a[1]+dx[a[3]],a[2]+dy[a[3]],a[3],a[0]+A);
			tri(a[1],a[2],4,dp[a[1]][a[2]][a[3]]);
		}
		else if(a[3]==4){
			tri(a[1],a[2],5,a[0]+C*dist[a[1]][a[2]]);
		}
		else{
			for(int i=0;i<=3;i++){
				tri(a[1],a[2],i,a[0]+B);
				tri(a[1]+dx[i],a[2]+dy[i],5,a[0]+C);
			}
			tri(a[1],a[2],4,a[0]);
		}
	}
	printf("%lld\n",dp[s[n]][t[n]][4]);
}
int main(){
	scanf("%lld %lld %lld %lld %lld %lld",&h,&w,&A,&B,&C,&n);
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			dist[i][j]=inf;
			for(int k=0;k<=5;k++) dp[i][j][k]=inf;
		}
	}
	for(int i=1;i<=n;i++){
		scanf("%lld %lld",&s[i],&t[i]);
		qq.push(mp(0,mp(s[i],t[i])));
		dist[s[i]][t[i]]=0;
	}
	while(!qq.empty()){
		iii temp=qq.front();
		qq.pop();
		ii seh=temp.se;
		lo int cst=temp.fi;
		dist[seh.fi][seh.se]=cst;
		for(int i=0;i<=3;i++){
			lo int gox=dx[i]+seh.fi;
			lo int goy=dy[i]+seh.se;
			if(gox<0 || goy<0 || gox>h || goy>w || dist[gox][goy]!=inf) continue;
			dist[gox][goy]=cst+1;
			qq.push(mp(cst+1,mp(gox,goy)));
		}
	}
	//~ for(int i=0;i<=h;i++){
		//~ for(int j=0;j<=w;j++){
			//~ printf("%lld ",dist[i][j]);
		//~ }
		//~ printf("\n");
	//~ }
	bfs();
	return 0;
}

Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld %lld %lld %lld",&h,&w,&A,&B,&C,&n);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&s[i],&t[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 7860 KB Output is correct
2 Correct 2 ms 7860 KB Output is correct
3 Correct 516 ms 22824 KB Output is correct
4 Correct 527 ms 22824 KB Output is correct
5 Correct 125 ms 22824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 679 ms 22824 KB Output is correct
2 Correct 605 ms 22848 KB Output is correct
3 Correct 444 ms 22848 KB Output is correct
4 Correct 434 ms 22848 KB Output is correct
5 Correct 498 ms 22848 KB Output is correct
6 Correct 466 ms 22872 KB Output is correct
7 Correct 613 ms 23144 KB Output is correct
8 Correct 528 ms 23144 KB Output is correct
9 Correct 644 ms 23232 KB Output is correct
10 Correct 101 ms 23232 KB Output is correct
11 Correct 613 ms 23244 KB Output is correct
12 Correct 614 ms 23244 KB Output is correct
13 Correct 347 ms 23244 KB Output is correct
14 Correct 645 ms 23404 KB Output is correct
15 Correct 483 ms 23404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 7860 KB Output is correct
2 Correct 2 ms 7860 KB Output is correct
3 Correct 516 ms 22824 KB Output is correct
4 Correct 527 ms 22824 KB Output is correct
5 Correct 125 ms 22824 KB Output is correct
6 Correct 679 ms 22824 KB Output is correct
7 Correct 605 ms 22848 KB Output is correct
8 Correct 444 ms 22848 KB Output is correct
9 Correct 434 ms 22848 KB Output is correct
10 Correct 498 ms 22848 KB Output is correct
11 Correct 466 ms 22872 KB Output is correct
12 Correct 613 ms 23144 KB Output is correct
13 Correct 528 ms 23144 KB Output is correct
14 Correct 644 ms 23232 KB Output is correct
15 Correct 101 ms 23232 KB Output is correct
16 Correct 613 ms 23244 KB Output is correct
17 Correct 614 ms 23244 KB Output is correct
18 Correct 347 ms 23244 KB Output is correct
19 Correct 645 ms 23404 KB Output is correct
20 Correct 483 ms 23404 KB Output is correct
21 Correct 141 ms 23404 KB Output is correct
22 Correct 710 ms 23404 KB Output is correct
23 Correct 662 ms 23404 KB Output is correct
24 Correct 760 ms 23404 KB Output is correct
25 Correct 611 ms 23404 KB Output is correct
26 Correct 661 ms 23684 KB Output is correct
27 Correct 434 ms 23684 KB Output is correct
28 Correct 425 ms 23684 KB Output is correct
29 Correct 647 ms 24428 KB Output is correct
30 Correct 395 ms 24428 KB Output is correct
31 Correct 652 ms 26228 KB Output is correct
32 Correct 760 ms 30028 KB Output is correct
33 Correct 493 ms 30028 KB Output is correct
34 Correct 723 ms 30028 KB Output is correct
35 Correct 371 ms 30028 KB Output is correct