結果

問題 No.989 N×Mマス計算(K以上)
ユーザー jp_stejp_ste
提出日時 2020-05-05 20:32:43
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 2,435 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 5,504 KB
実行使用メモリ 56,752 KB
最終ジャッジ日時 2024-04-21 03:26:42
合計ジャッジ時間 3,367 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
38,784 KB
testcase_01 AC 62 ms
38,656 KB
testcase_02 AC 60 ms
38,784 KB
testcase_03 AC 59 ms
38,528 KB
testcase_04 AC 60 ms
38,784 KB
testcase_05 AC 60 ms
38,656 KB
testcase_06 AC 63 ms
38,784 KB
testcase_07 AC 60 ms
38,784 KB
testcase_08 AC 61 ms
38,656 KB
testcase_09 AC 59 ms
38,912 KB
testcase_10 AC 187 ms
48,812 KB
testcase_11 AC 186 ms
50,220 KB
testcase_12 AC 210 ms
50,776 KB
testcase_13 AC 141 ms
47,992 KB
testcase_14 AC 272 ms
56,752 KB
testcase_15 AC 113 ms
46,088 KB
testcase_16 AC 166 ms
49,132 KB
testcase_17 AC 143 ms
47,980 KB
testcase_18 AC 136 ms
47,840 KB
testcase_19 AC 188 ms
50,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(input) {
  let [N, M, K] = getIntegers(input, " ");
  let B = getIntegers(input, " ");
  let op = B.shift();
  let A = getIntegers(input);
  B.sort((a,b)=>b-a);
  A.sort((a,b)=>a-b);
  
  let i=0, j=0, sum=0;
  while(j < M && i < N) {
    let val = op == '+' ? A[i]+B[j] : A[i]*B[j];
    if(val >= K) {
      j++;
      if(j==M) {
        sum += (N-i)*j;
        break;
      }
    } else {
      sum += j;
      i++;
    }
  }
  console.log(sum);
}

//-- functions ------------------------------------

function getIntegers(lines, sep) {
  if(sep === undefined) {
    return lines.map(function(e) {
      return Number(e);
    });  
  } else {
    return lines.shift().split(sep).map(function(e) {
      if(e == '+' || e == '*') return e;
      return Number(e);
    });  
  }
}

function getBigIntegers(lines, sep=" ") {
  return lines.shift().split(sep).map(function(e) {
    return BigInt(e);
  });
}

function getStrings(lines, sep=" ") {
  return lines.shift().split(sep);
}

function twoDimenArrayByValue(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;
}

function twoDimenArrayByStrings(h, strings) {
  const list = new Array(h);
  for(let i=0; i<h; i++) {
    list[i] = strings.shift().split("");
  }
  return list;
}

function distance(x1, y1, x2, y2) {
  return Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
}

function gcd(a, b) {
  return b === 0 ? a : gcd(b, a % b);
}

//-- Array -------------------------------------------

Array.prototype.deepCopy = function(list) {
  let retList = [];
  for(let i=0; i<list.length; i++) {
    retList[i] = list[i].constructor == Array ? Array.from(list[i]) : list[i];
  }
  return retList;
};

Array.prototype.out = function() {
  let outList = [];
  if(this[0].constructor == Array) {
    for(let i=0; i<this.length; i++) {
      outList.push(this[i].join(" "));
    } 
  } else {
    outList.push(this.join(" "));
  }
  console.log(outList.join("\n"));
};

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;
  });
};

main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));
0