問題一覧 > 通常問題

No.496 Warp Crystal (Before Payday Edition)

レベル : / AI推定難易度 : 875 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 194
作問者 : Tawara / テスター : 37zigen
お気に入りにしたユーザー ProblemId : 934 / 自分の提出
問題文最終更新日: 2020-09-10 09:12:13
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 159 (順位表) の他の問題:

Problem Statement

Crystal City is a town famous for the use of warp crystals, which let you move to another place instantly.
However, you cannot move to an arbitrary position: for each crystal, the relative position you can move to from your current location is fixed.

  • Crystal City is a town made up of square blocks laid out in a grid.
    Each block is represented by integer coordinates $(x,y)$, where east and north correspond to the positive directions of the $x$-axis and the $y$-axis, respectively.
  • Each warp crystal has a relative position $(x,y)$ ($x,y$ are integers) written on it,
    and using it at block $(X_1,Y_1)$ lets you warp to block $(X_1+x,Y_1+y)$.
  • From a block, you can move on foot only to an adjacent block to the east, west, south, or north.
    Each such move requires paying a fixed toll.
Chris, who lives at block $(0,0)$, is about to go out to block $(G_x,G_y)$ ($G_x,G_y \ge 0$).
Since it is just before payday, Chris wants to save as much as possible on the total of the prices of the crystals he uses and the tolls he pays until he reaches the destination.
Chris is bad at calculations, so on his behalf, please compute the minimum cost to reach the destination.

However, today Chris seems to dislike any movement that takes him backward relative to the destination.
Therefore, please compute under the assumption that no moves are made to a block in the west or south direction from the current location.

Added at 22:48: A crystal disappears once it is used.

Input

$G_x \ G_y \ N \ F$
$x_1 \ y_1 \  c_1$
$\vdots$
$x_N \ y_N \ c_N$

The input is given separated by spaces.
The first line contains the coordinates $(G_x, G_y)$ of the destination block, the number $N$ of crystals Chris has, and the toll $F$ for moving on foot to an adjacent block.
From the 2nd line to the $N+1$-th line, the relative position $(x_i,y_i)$ that each crystal can move to and its price $c_i$ are given.

All inputs are integers and satisfy the following constraints.
$ 0 \le Gx,Gy \le 100$
$ 0 \le N \le 50 $
$ 1 \le F \le 200 $
$0 \le x_i \le Gx$, $0 \le y_i \le Gy$, $ (x_i, y_i) \neq (0,0) $
$1 \le c_i \le 200 $
As the constraints also show, today Chris does not use crystals that move west or south.
As stated in the problem statement, he also does not move on foot to a block to the west or south.

Output

Output the minimum cost for Chris to get from $(0,0)$ to $(Gx,Gy)$. Print a newline at the end.

Sample

Sample 1
Input
3 3 2 1
1 2 2
2 1 2
Output
4

For example, moving using only crystals as shown below minimizes the cost.

Sample 2
Input
3 3 2 1
1 2 2
2 1 4
Output
5

Walking costs less than using the second crystal.

Sample 3
Input
5 3 5 2
5 0 6
5 0 6
2 2 6
0 2 3
3 1 6
Output
11

Using the 3rd and 5th crystals lets him reach the destination without walking, but the cost in that case is 12, which is not the minimum.
Also, there may be multiple completely identical crystals.

Sample 4
Input
5 3 5 1
5 0 6
5 0 6
2 2 6
0 2 3
3 1 6
Output
8

The toll is cheap, so he decided to make the effort and walk.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。