Find the Route!

AtCoder
IDs8pc_4_f
Time2000ms
Memory256MB
Difficulty
There is a grid which size is $H \\times W$. the upper-left cell is $(1,1)$ and the lower-right cell is $(H,W)$. There is $N$ arrows. Arrow which start point is $(a_i,b_i)$ of direction is $c_i$, and size is $d_i$. ($d_i$ may be negative) It is guaranteed that there are no two arrow which start point is same. Sothe want to move from cell $(sx,sy)$ to cell $(gx,gy)$ with arrows. But it may not possible to move to goal in initial grid. So, Snuke decided to change some arrows. ![image](https://atcoder.jp/img/s8pc-4/5eff69da8ebd635a501515b7f86a47e6.png) Sothe can change each arrow as follows: * He can't change the start point of this arrow. * It costs $e_i$ if he change the direction of this arrow. * It costs $f \\times |d_i-G|$ if he change $d_i$ to $G$. ![image](https://atcoder.jp/img/s8pc-4/532f821bbe6594a29e622d7a81cbcad7.png) He can't add or erase arrows. Please calculate the minimum cost that he can move to $(gx,gy)$. ### If he can't move to goal, please output '-1'. Note: Arrows are directed, and he can't turn in the middle of the arrow. ## Input The input is given from standard input in the following format. $H$ $W$ $N$ $f$ $sx$ $sy$ $gx$ $gy$ $a_1$ $b_1$ $c_1$ $d_1$ $e_1$ $a_2$ $b_2$ $c_2$ $d_2$ $e_2$ : : : $a_N$ $b_N$ $c_N$ $d_N$ $e_N$ [samples]
API Response (JSON)
{
  "problem": {
    "name": "Find the Route!",
    "description": {
      "content": "There is a grid which size is $H \\\\times W$. the upper-left cell is $(1,1)$ and the lower-right cell is $(H,W)$.   There is $N$ arrows. Arrow which start point is $(a_i,b_i)$ of direction is $c_i$, an",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "s8pc_4_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a grid which size is $H \\\\times W$. the upper-left cell is $(1,1)$ and the lower-right cell is $(H,W)$.  \nThere is $N$ arrows. Arrow which start point is $(a_i,b_i)$ of direction is $c_i$, an...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments