結果

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

コンパイルメッセージ
main.ts(5,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
main.ts(6,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
main.ts(11,46): error TS2345: Argument of type 'any[]' is not assignable to parameter of type 'never'.
main.ts(20,20): error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
main.ts(21,63): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.

ソースコード

diff #
raw source code

const input = require('fs').readFileSync(0, 'utf-8').trim().split(/\s+/).map(Number);
let idx = 0;

const [N, C, V] = [input[idx++], input[idx++], input[idx++]];
const S = input.slice(idx, idx + V).map(x => x - 1); idx += V;
const T = input.slice(idx, idx + V).map(x => x - 1); idx += V;
const Y = input.slice(idx, idx + V); idx += V;
const M = input.slice(idx, idx + V); idx += V;

const graph = Array.from({length: N}, () => []);
for (let i = 0; i < V; i++) graph[S[i]].push([T[i], Y[i], M[i]]);

const INF = 1e9;
const dp = Array.from({length: N}, () => Array(C + 1).fill(INF));
dp[0][C] = 0;

for (let i = 0; i < N; i++) {
    for (let k = C; k >= 0; k--) {
        if (dp[i][k] === INF) continue;
        for (const [t, c, tm] of graph[i]) {
            if (k >= c) dp[t][k - c] = Math.min(dp[t][k - c], dp[i][k] + tm);
        }
    }
}

const result = Math.min(...dp[N - 1]);
console.log(result === INF ? -1 : result);
0