結果

問題 No.988 N×Mマス計算(総和)
ユーザー jp_stejp_ste
提出日時 2020-05-10 20:35:46
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 3,044 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 5,340 KB
実行使用メモリ 81,976 KB
最終ジャッジ日時 2023-09-20 12:24:48
合計ジャッジ時間 4,860 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
41,780 KB
testcase_01 AC 78 ms
41,824 KB
testcase_02 AC 80 ms
42,260 KB
testcase_03 AC 78 ms
41,592 KB
testcase_04 AC 78 ms
42,204 KB
testcase_05 AC 79 ms
41,812 KB
testcase_06 AC 77 ms
41,620 KB
testcase_07 AC 78 ms
41,628 KB
testcase_08 AC 80 ms
43,888 KB
testcase_09 AC 79 ms
41,848 KB
testcase_10 AC 307 ms
53,680 KB
testcase_11 AC 176 ms
60,808 KB
testcase_12 AC 227 ms
67,904 KB
testcase_13 AC 166 ms
59,784 KB
testcase_14 AC 145 ms
53,764 KB
testcase_15 AC 150 ms
56,432 KB
testcase_16 AC 233 ms
70,280 KB
testcase_17 AC 252 ms
68,608 KB
testcase_18 AC 171 ms
59,800 KB
testcase_19 AC 244 ms
70,268 KB
testcase_20 AC 312 ms
81,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(input) {
  let [N, M, K] = getIntegers(input, " ");
  let l = getStrings(input, " ");
  let op = l.shift();
  let B = l.map(x=>BigInt(x));
  let A = getIntegers(input);
  let ans = 0n;
  
  if(op == '+') {
    let sum = 0n;
    for(let i=0; i<N; i++) {
      sum += A[i] * M;
    }
    for(let i=0; i<M; i++) {
      sum += B[i] * N;
    }
    ans = sum % K;
    
  } else {
    let sumA = 0n, sumB = 0n;
    for(let i=0; i<N; i++) {
      sumA += A[i];
    }
    for(let i=0; i<M; i++) {
      sumB += B[i]; 
    }
    ans = sumA * sumB % K;
  }
  console.log(ans.toString());
}

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

function getIntegers(lines, sep) {
  if(sep === undefined) {
    return lines.map(function(e) {
      return BigInt(e);
    });  
  } else {
    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.sortByIntegerA = function() {
  this.sort(function(a, b) { return a - b; });
};

Array.prototype.sortByIntegerD = function() {
  this.sort(function(a, b) { return b - a; });
};

Array.prototype.orLess = function(V, l=0, r=this.length) {
  l--;
  while(r - l > 1) {
    let x = Math.floor((r + l) / 2);
    this[x] > V ? r = x : l = x;
  }
  return r;
};

Array.prototype.lessThen = function(V, l=0, r=this.length) {
  l--;
  while(r - l > 1) {
    let x = Math.floor((r + l) / 2);
    this[x] >= V ? r = x : l = x;
  }
  return r;
};

Array.prototype.orHigher = function(V, l, r) {
  return this.length - this.lessThen(V, l, r);
};

Array.prototype.greaterThan = function(V, l, r) {
  return this.length - this.orLess(V, l, r);
};

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

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