結果

問題 No.1 道のショートカット
コンテスト
ユーザー monaka
提出日時 2022-02-01 19:26:15
言語 TypeScript
(6.0.2)
コンパイル:
tsc.sh -p tsconfig.json
実行:
node main.js ONLINE_JUDGE
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,152 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,396 ms
コンパイル使用メモリ 349,712 KB
最終ジャッジ日時 2026-06-05 06:02:07
合計ジャッジ時間 6,372 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.ts(2,15): error TS7006: Parameter 'line' implicitly has an 'any' type.
main.ts(6,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
main.ts(7,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
main.ts(8,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
main.ts(9,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
main.ts(18,16): error TS18048: 'now' is possibly 'undefined'.
main.ts(19,19): error TS18048: 'now' is possibly 'undefined'.
main.ts(20,18): error TS18048: 'now' is possibly 'undefined'.

ソースコード

diff #
raw source code

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"));

0