답안 #173489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173489 2020-01-04T09:18:41 Z dennisstar Soccer (JOI17_soccer) C++11
100 / 100
495 ms 22884 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

struct dat {
	int x, y, ty; ll d;
	bool operator <(const dat &r)const{ return d>r.d; }
};

int xx[]={1, -1, 0, 0}, yy[]={0, 0, 1, -1};

int H, W, N;
ll A, B, C;
int D1[510][510]; ll D2[510][510][5];
int S[100010], T[100010];
pii stk[500010]; int tp;
int chk[510][510];

bool pos(int x, int y) { return (0<=x&&x<=H&&0<=y&&y<=W); }

priority_queue<dat> pq;
void push_pq(int x, int y, int ty, ll d) {
	if (!pos(x, y)) return ;
	if (D2[x][y][ty]>d) { D2[x][y][ty]=d; pq.push({x, y, ty, d}); }
}

int main() {
	scanf("%d %d %lld %lld %lld %d", &H, &W, &A, &B, &C, &N);
	for (int i=0; i<=H; i++) for (int j=0; j<W; j++) D1[i][j]=(1<<30);
	for (int i=1; i<=N; i++) {
		scanf("%d %d", &S[i], &T[i]);
		stk[tp++]={S[i], T[i]};
		D1[S[i]][T[i]]=0;
		chk[S[i]][T[i]]=1;
	}
	
	pii pl;
	for (int i=0; i<tp; i++) {
		pl=stk[i];
		for (int j=0; j<4; j++) if (pos(pl.fi+xx[j], pl.se+yy[j]) && !chk[pl.fi+xx[j]][pl.se+yy[j]]) {
			stk[tp++]={pl.fi+xx[j], pl.se+yy[j]};
			D1[pl.fi+xx[j]][pl.se+yy[j]]=D1[pl.fi][pl.se]+1;
			chk[pl.fi+xx[j]][pl.se+yy[j]]=1;
		}
	}
	
	for (int i=0; i<=H; i++) for (int j=0; j<=W; j++) for (int k=0; k<5; k++) D2[i][j][k]=(1ll<<60);
	push_pq(S[1], T[1], 4, 0);

	while (!pq.empty()) {
		auto dt=pq.top(); pq.pop();
		if (D2[dt.x][dt.y][dt.ty]!=dt.d) continue;
		if (dt.ty==4) for (int i=0; i<4; i++) push_pq(dt.x, dt.y, i, dt.d+B), push_pq(dt.x+xx[i], dt.y+yy[i], 4, dt.d+C);
		else push_pq(dt.x+xx[dt.ty], dt.y+yy[dt.ty], dt.ty, dt.d+A), push_pq(dt.x, dt.y, 4, dt.d+D1[dt.x][dt.y]*C);
	}
	printf("%lld\n", D2[S[N]][T[N]][4]);
	return 0;
}

Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %lld %lld %lld %d", &H, &W, &A, &B, &C, &N);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &S[i], &T[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 7280 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 316 ms 20580 KB Output is correct
4 Correct 347 ms 20680 KB Output is correct
5 Correct 60 ms 7648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 380 ms 20580 KB Output is correct
2 Correct 338 ms 20576 KB Output is correct
3 Correct 263 ms 17760 KB Output is correct
4 Correct 270 ms 20708 KB Output is correct
5 Correct 257 ms 20064 KB Output is correct
6 Correct 291 ms 20576 KB Output is correct
7 Correct 343 ms 20708 KB Output is correct
8 Correct 371 ms 20708 KB Output is correct
9 Correct 342 ms 20708 KB Output is correct
10 Correct 61 ms 7916 KB Output is correct
11 Correct 354 ms 20708 KB Output is correct
12 Correct 409 ms 20552 KB Output is correct
13 Correct 221 ms 17888 KB Output is correct
14 Correct 342 ms 20676 KB Output is correct
15 Correct 266 ms 20064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 7280 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 316 ms 20580 KB Output is correct
4 Correct 347 ms 20680 KB Output is correct
5 Correct 60 ms 7648 KB Output is correct
6 Correct 380 ms 20580 KB Output is correct
7 Correct 338 ms 20576 KB Output is correct
8 Correct 263 ms 17760 KB Output is correct
9 Correct 270 ms 20708 KB Output is correct
10 Correct 257 ms 20064 KB Output is correct
11 Correct 291 ms 20576 KB Output is correct
12 Correct 343 ms 20708 KB Output is correct
13 Correct 371 ms 20708 KB Output is correct
14 Correct 342 ms 20708 KB Output is correct
15 Correct 61 ms 7916 KB Output is correct
16 Correct 354 ms 20708 KB Output is correct
17 Correct 409 ms 20552 KB Output is correct
18 Correct 221 ms 17888 KB Output is correct
19 Correct 342 ms 20676 KB Output is correct
20 Correct 266 ms 20064 KB Output is correct
21 Correct 74 ms 7608 KB Output is correct
22 Correct 420 ms 20548 KB Output is correct
23 Correct 386 ms 16144 KB Output is correct
24 Correct 432 ms 17640 KB Output is correct
25 Correct 386 ms 20704 KB Output is correct
26 Correct 405 ms 20704 KB Output is correct
27 Correct 246 ms 15768 KB Output is correct
28 Correct 232 ms 16204 KB Output is correct
29 Correct 375 ms 19528 KB Output is correct
30 Correct 237 ms 16120 KB Output is correct
31 Correct 378 ms 20700 KB Output is correct
32 Correct 495 ms 22884 KB Output is correct
33 Correct 324 ms 20704 KB Output is correct
34 Correct 454 ms 20708 KB Output is correct
35 Correct 187 ms 16808 KB Output is correct