結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー tabataba
提出日時 2017-04-03 04:49:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,913 ms / 2,000 ms
コード長 597 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 8,712 KB
最終ジャッジ日時 2023-09-22 09:19:34
合計ジャッジ時間 5,191 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,840 KB
testcase_01 AC 16 ms
7,896 KB
testcase_02 AC 15 ms
7,844 KB
testcase_03 AC 15 ms
7,892 KB
testcase_04 AC 15 ms
7,952 KB
testcase_05 AC 15 ms
7,812 KB
testcase_06 AC 23 ms
8,712 KB
testcase_07 AC 16 ms
7,804 KB
testcase_08 AC 80 ms
8,632 KB
testcase_09 AC 1,913 ms
8,460 KB
testcase_10 AC 19 ms
8,336 KB
testcase_11 AC 20 ms
8,192 KB
testcase_12 AC 26 ms
8,372 KB
testcase_13 AC 32 ms
8,240 KB
testcase_14 AC 105 ms
8,272 KB
testcase_15 AC 29 ms
8,192 KB
testcase_16 AC 31 ms
8,436 KB
testcase_17 AC 52 ms
8,344 KB
testcase_18 AC 39 ms
8,300 KB
testcase_19 AC 52 ms
8,348 KB
testcase_20 AC 33 ms
8,320 KB
testcase_21 AC 23 ms
8,188 KB
testcase_22 AC 209 ms
8,644 KB
testcase_23 AC 242 ms
8,708 KB
testcase_24 AC 221 ms
8,548 KB
testcase_25 AC 177 ms
8,592 KB
testcase_26 AC 207 ms
8,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

gx,gy,n,f=map(int,input().split())
c=[list(map(int,input().split()))for _ in[0]*n]
gx+=1
gy+=1
d=[[1e99]*gx for _ in[0]*gy]
d[0][0]=0
def dp(x,y,u):
	if x>gx or y>gy:
		return
	for i in range(n):
		if u[i]:continue
		nx=x+c[i][0]
		ny=y+c[i][1]
		if nx<gx and ny<gy and d[y][x]+c[i][2]<d[ny][nx]:
			d[ny][nx]=d[y][x]+c[i][2]
			nu=u[:]
			nu[i]=True
			dp(nx,ny,nu)
	nx=x+1
	ny=y
	if nx<gx and ny<gy and d[y][x]+f<d[ny][nx]:
		d[ny][nx]=d[y][x]+f
		dp(nx,ny,u[:])
	nx=x
	ny=y+1
	if nx<gx and ny<gy and d[y][x]+f<d[ny][nx]:
		d[ny][nx]=d[y][x]+f
		dp(nx,ny,u[:])
dp(0,0,[False]*n)
print(d[-1][-1])
0