結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
monaka
|
| 提出日時 | 2022-02-01 19:26:15 |
| 言語 | TypeScript (5.7.2) |
| 結果 |
AC
|
| 実行時間 | 106 ms / 5,000 ms |
| コード長 | 1,152 bytes |
| コンパイル時間 | 8,495 ms |
| コンパイル使用メモリ | 229,076 KB |
| 実行使用メモリ | 46,048 KB |
| 最終ジャッジ日時 | 2024-12-31 16:45:08 |
| 合計ジャッジ時間 | 12,935 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
function main(line) {
const n = Number(line.shift());
const c = Number(line.shift());
const v = Number(line.shift());
const s = line.shift().split(" ").map(x=>Number(x)-1);
const t = line.shift().split(" ").map(x=>Number(x)-1);
const y = line.shift().split(" ").map(x=>Number(x));
const m = line.shift().split(" ").map(x=>Number(x));
const arr = [];
for(let i=0; i<v; i++) {
arr.push({s:s[i], t:t[i], y:y[i], m:m[i]});
}
const q = [{id:0, money:c, cost:0}];
let minCost = Number.MAX_SAFE_INTEGER;
while(q.length > 0) {
const now = q.shift();
const id = now.id;
const money = now.money;
const cost = now.cost;
if(cost > minCost) continue;
if(id === n-1) {
if(cost < minCost) {
minCost = cost;
}
}
arr.filter(cur => cur.s === id).forEach(cur => {
const nextMoney = money - cur.y;
if(nextMoney >= 0) {
const nextCost = cost + cur.m;
q.push({id:cur.t, money:nextMoney, cost:nextCost});
}
});
}
console.log(minCost === Number.MAX_SAFE_INTEGER ? -1 : minCost);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));
monaka