結果

問題 No.92 逃走経路
ユーザー jp_stejp_ste
提出日時 2020-04-20 14:41:52
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 382 ms / 5,000 ms
コード長 1,859 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 46,976 KB
最終ジャッジ日時 2024-04-21 03:24:06
合計ジャッジ時間 4,655 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
46,976 KB
testcase_01 AC 70 ms
39,168 KB
testcase_02 AC 67 ms
39,552 KB
testcase_03 AC 73 ms
39,168 KB
testcase_04 AC 68 ms
39,296 KB
testcase_05 AC 78 ms
44,800 KB
testcase_06 AC 78 ms
44,288 KB
testcase_07 AC 81 ms
44,416 KB
testcase_08 AC 87 ms
44,928 KB
testcase_09 AC 373 ms
45,952 KB
testcase_10 AC 302 ms
46,080 KB
testcase_11 AC 305 ms
46,464 KB
testcase_12 AC 382 ms
46,464 KB
testcase_13 AC 213 ms
46,080 KB
testcase_14 AC 233 ms
45,824 KB
testcase_15 AC 277 ms
46,080 KB
testcase_16 AC 226 ms
46,080 KB
testcase_17 AC 235 ms
46,336 KB
testcase_18 AC 132 ms
45,312 KB
testcase_19 AC 92 ms
44,672 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 value.constructor == Array ? Array.from(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