結果
問題 | No.92 逃走経路 |
ユーザー | jp_ste |
提出日時 | 2020-04-20 14:05:20 |
言語 | JavaScript (node v21.7.1) |
結果 |
AC
|
実行時間 | 1,341 ms / 5,000 ms |
コード長 | 1,724 bytes |
コンパイル時間 | 30 ms |
コンパイル使用メモリ | 6,684 KB |
実行使用メモリ | 48,512 KB |
最終ジャッジ日時 | 2024-04-21 03:23:57 |
合計ジャッジ時間 | 12,000 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 869 ms
47,616 KB |
testcase_01 | AC | 72 ms
39,296 KB |
testcase_02 | AC | 71 ms
39,424 KB |
testcase_03 | AC | 71 ms
39,424 KB |
testcase_04 | AC | 71 ms
39,168 KB |
testcase_05 | AC | 82 ms
44,288 KB |
testcase_06 | AC | 94 ms
44,160 KB |
testcase_07 | AC | 93 ms
44,416 KB |
testcase_08 | AC | 129 ms
45,824 KB |
testcase_09 | AC | 1,323 ms
48,128 KB |
testcase_10 | AC | 585 ms
46,080 KB |
testcase_11 | AC | 750 ms
46,592 KB |
testcase_12 | AC | 1,341 ms
48,512 KB |
testcase_13 | AC | 762 ms
46,592 KB |
testcase_14 | AC | 841 ms
46,976 KB |
testcase_15 | AC | 951 ms
47,232 KB |
testcase_16 | AC | 770 ms
47,232 KB |
testcase_17 | AC | 790 ms
47,616 KB |
testcase_18 | AC | 316 ms
45,440 KB |
testcase_19 | AC | 146 ms
44,928 KB |
ソースコード
function main(input) { const [n, m, k] = getIntegers(input); const mList = twoDimensionalArray(n, n, []); for(let i=0; i<m; i++) { const [p1, p2, cost] = getIntegers(input); mList[p1-1][p2-1].push(cost); mList[p2-1][p1-1].push(cost); } const kList = getIntegers(input); let ansSet = new Set(); for(let i=0; i<n; i++) { for(let j=0; j<n; j++) { if(mList[i][j].indexOf(kList[0]) >= 0) { ansSet.add(j+1); } } } for(let i=1; i<k; i++) { const nextK = kList[i]; let nextAnsSet = new Set(); ansSet.forEach(function(from) { for(let to=0; to<n; to++) { if(mList[from-1][to].indexOf(nextK) >= 0) { nextAnsSet.add(to+1); } } }); ansSet = nextAnsSet; } const ansList = Array.from(ansSet); ansList.sortByIntegers(); console.log(ansList.length); console.log(ansList.oneLineString()); } //my functions ------------------------------------ function getIntegers(lines) { return lines.shift().split(" ").map(function(e) { return Number(e); }); } function getStrings(lines) { return lines.shift().split(" "); } function twoDimensionalArray(h, w, value) { const list = new Array(h); for(let i=0; i<h; i++) { list[i] = new Array(w).fill().map(function(e) { return (typeof value) == "object" ? Object.create(value) : value; }); } return list; } Array.prototype.sortByIntegers = function() { this.sort(function(a, b) { return a - b; }); }; Array.prototype.oneLineString = function() { let str = ""; this.forEach(function(e, i) { if(i > 0) str += " "; str += e; }); return str; }; main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));