답안 #334914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334914 2020-12-10T08:54:13 Z YJU Soccer (JOI17_soccer) C++14
100 / 100
659 ms 20064 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
typedef pair<ll,pair<int,pll> > plll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=5e2+5;
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

queue<pll> q;
ll cost[N][N],dis[5][N][N],d;
int n,a,b,c;
int H,W,sx,sy,ex,ey,x,y,ty;
int dx[5]={0,-1,0,0,1},dy[5]={0,0,-1,1,0};
priority_queue<plll,vector<plll>,greater<plll> > pq;

bool ck(short nx,short ny){
	return (nx>=0&&nx<=H&&ny>=0&&ny<=W);
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>H>>W;
	cin>>a>>b>>c;
	cin>>n;
	memset(dis,-1,sizeof(dis));
	REP1(i,n)cin>>x>>y,q.push(mp(x,y)),cost[x][y]=0,dis[0][x][y]=INF,sx=(i==1?x:sx),sy=(i==1?y:sy);
	ex=x;ey=y;
	while(SZ(q)){
		x=q.front().X;y=q.front().Y;q.pop();
		REP1(i,4){
			if(ck(x+dx[i],y+dy[i])&&dis[0][x+dx[i]][y+dy[i]]==-1){
				dis[0][x+dx[i]][y+dy[i]]=INF;
				cost[x+dx[i]][y+dy[i]]=cost[x][y]+c;
				q.push(mp(x+dx[i],y+dy[i]));
			}
		}
	}
	
	REP(ii,5)REP(i,H+1)REP(j,W+1)dis[ii][i][j]=INF;
	
	pq.push(mp(dis[0][sx][sy]=0,mp(0,mp(sx,sy))));
	while(SZ(pq)){
		d=pq.top().X,ty=pq.top().Y.X,x=pq.top().Y.Y.X,y=pq.top().Y.Y.Y;pq.pop();
		if(dis[ty][x][y]!=d)continue;
		if(ty==0){
			REP1(i,4){
				ll nx=x+dx[i],ny=y+dy[i];
				if(ck(nx,ny)&&dis[ty][nx][ny]>d+c){
					pq.push(mp(dis[ty][nx][ny]=d+c,mp(ty,mp(nx,ny))));
				}
				if(ck(nx,ny)&&dis[i][nx][ny]>d+b+a){
					pq.push(mp(dis[i][nx][ny]=d+b+a,mp(i,mp(nx,ny))));
				}
			}
		}else{
			if(dis[0][x][y]>d+cost[x][y])pq.push(mp(dis[0][x][y]=d+cost[x][y],mp(0,mp(x,y))));
			ll nx=x+dx[ty],ny=y+dy[ty];
			if(ck(nx,ny)&&dis[ty][nx][ny]>d+a)pq.push(mp(dis[ty][nx][ny]=d+a,mp(ty,mp(nx,ny))));
		}
	}
	cout<<dis[0][ex][ey]<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 13160 KB Output is correct
2 Correct 6 ms 10348 KB Output is correct
3 Correct 377 ms 18784 KB Output is correct
4 Correct 377 ms 18656 KB Output is correct
5 Correct 102 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 18656 KB Output is correct
2 Correct 423 ms 18676 KB Output is correct
3 Correct 315 ms 18276 KB Output is correct
4 Correct 311 ms 18708 KB Output is correct
5 Correct 316 ms 18972 KB Output is correct
6 Correct 348 ms 18652 KB Output is correct
7 Correct 411 ms 18700 KB Output is correct
8 Correct 382 ms 18676 KB Output is correct
9 Correct 426 ms 18936 KB Output is correct
10 Correct 72 ms 14076 KB Output is correct
11 Correct 430 ms 18700 KB Output is correct
12 Correct 442 ms 18676 KB Output is correct
13 Correct 253 ms 18276 KB Output is correct
14 Correct 422 ms 18700 KB Output is correct
15 Correct 343 ms 18676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 13160 KB Output is correct
2 Correct 6 ms 10348 KB Output is correct
3 Correct 377 ms 18784 KB Output is correct
4 Correct 377 ms 18656 KB Output is correct
5 Correct 102 ms 12012 KB Output is correct
6 Correct 431 ms 18656 KB Output is correct
7 Correct 423 ms 18676 KB Output is correct
8 Correct 315 ms 18276 KB Output is correct
9 Correct 311 ms 18708 KB Output is correct
10 Correct 316 ms 18972 KB Output is correct
11 Correct 348 ms 18652 KB Output is correct
12 Correct 411 ms 18700 KB Output is correct
13 Correct 382 ms 18676 KB Output is correct
14 Correct 426 ms 18936 KB Output is correct
15 Correct 72 ms 14076 KB Output is correct
16 Correct 430 ms 18700 KB Output is correct
17 Correct 442 ms 18676 KB Output is correct
18 Correct 253 ms 18276 KB Output is correct
19 Correct 422 ms 18700 KB Output is correct
20 Correct 343 ms 18676 KB Output is correct
21 Correct 116 ms 12396 KB Output is correct
22 Correct 574 ms 18692 KB Output is correct
23 Correct 543 ms 15376 KB Output is correct
24 Correct 650 ms 15832 KB Output is correct
25 Correct 515 ms 18696 KB Output is correct
26 Correct 563 ms 18816 KB Output is correct
27 Correct 292 ms 13932 KB Output is correct
28 Correct 390 ms 14188 KB Output is correct
29 Correct 509 ms 16996 KB Output is correct
30 Correct 322 ms 13932 KB Output is correct
31 Correct 494 ms 18676 KB Output is correct
32 Correct 659 ms 20064 KB Output is correct
33 Correct 415 ms 18652 KB Output is correct
34 Correct 647 ms 18700 KB Output is correct
35 Correct 289 ms 14000 KB Output is correct