結果

問題 No.92 逃走経路
ユーザー jp_stejp_ste
提出日時 2020-04-20 13:49:25
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 1,393 ms / 5,000 ms
コード長 1,862 bytes
コンパイル時間 30 ms
コンパイル使用メモリ 5,120 KB
実行使用メモリ 47,104 KB
最終ジャッジ日時 2024-04-21 03:23:40
合計ジャッジ時間 11,379 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 843 ms
46,720 KB
testcase_01 AC 63 ms
39,040 KB
testcase_02 AC 63 ms
39,168 KB
testcase_03 AC 63 ms
39,168 KB
testcase_04 AC 66 ms
39,168 KB
testcase_05 AC 81 ms
44,160 KB
testcase_06 AC 85 ms
44,288 KB
testcase_07 AC 85 ms
44,288 KB
testcase_08 AC 118 ms
46,080 KB
testcase_09 AC 1,393 ms
46,592 KB
testcase_10 AC 618 ms
45,824 KB
testcase_11 AC 752 ms
46,336 KB
testcase_12 AC 1,365 ms
47,104 KB
testcase_13 AC 764 ms
46,200 KB
testcase_14 AC 822 ms
46,464 KB
testcase_15 AC 936 ms
46,208 KB
testcase_16 AC 766 ms
46,336 KB
testcase_17 AC 758 ms
46,336 KB
testcase_18 AC 311 ms
45,440 KB
testcase_19 AC 134 ms
44,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 ansList = [];
  for(let i=0; i<n; i++) {
    for(let j=0; j<n; j++) {
      if(mList[i][j].indexOf(kList[0]) >= 0) {
        ansList.pushNoSameValue(j+1);
      }
    }
  }
  for(let i=1; i<k; i++) {
    const nextK = kList[i];
    let nextAnsList = [];
    ansList.forEach(function(from) {
      for(let to=0; to<n; to++) {
        if(mList[from-1][to].indexOf(nextK) >= 0) {
          nextAnsList.pushNoSameValue(to+1);
        }
      }   
    });
    ansList = nextAnsList;
  }
  
  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.pushNoSameValue = function(...values) {
  values.forEach(function(e) {
    if(!this.includes(e)) {
      this.push(e);
    }
  }, this);
};

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