結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-09-04 21:22:02 |
| 言語 | TypeScript (5.7.2) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 5,000 ms |
| コード長 | 925 bytes |
| コンパイル時間 | 10,750 ms |
| コンパイル使用メモリ | 267,564 KB |
| 実行使用メモリ | 54,780 KB |
| 最終ジャッジ日時 | 2025-09-04 21:22:18 |
| 合計ジャッジ時間 | 15,428 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
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);
vjudge1