結果
問題 | No.9 モンスターのレベル上げ |
ユーザー | jp_ste |
提出日時 | 2020-05-14 17:10:51 |
言語 | JavaScript (node v21.7.1) |
結果 |
AC
|
実行時間 | 1,414 ms / 5,000 ms |
コード長 | 2,720 bytes |
コンパイル時間 | 76 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 53,104 KB |
最終ジャッジ日時 | 2024-10-13 01:54:33 |
合計ジャッジ時間 | 14,646 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
39,040 KB |
testcase_01 | AC | 65 ms
39,168 KB |
testcase_02 | AC | 1,218 ms
51,816 KB |
testcase_03 | AC | 1,032 ms
52,188 KB |
testcase_04 | AC | 731 ms
51,944 KB |
testcase_05 | AC | 603 ms
51,820 KB |
testcase_06 | AC | 298 ms
47,616 KB |
testcase_07 | AC | 118 ms
45,864 KB |
testcase_08 | AC | 359 ms
48,868 KB |
testcase_09 | AC | 1,190 ms
53,012 KB |
testcase_10 | AC | 61 ms
39,168 KB |
testcase_11 | AC | 1,240 ms
52,224 KB |
testcase_12 | AC | 1,414 ms
52,308 KB |
testcase_13 | AC | 1,026 ms
51,944 KB |
testcase_14 | AC | 1,203 ms
52,412 KB |
testcase_15 | AC | 1,119 ms
53,104 KB |
testcase_16 | AC | 162 ms
45,960 KB |
testcase_17 | AC | 849 ms
51,948 KB |
testcase_18 | AC | 787 ms
52,196 KB |
testcase_19 | AC | 131 ms
46,004 KB |
ソースコード
function main(input) { let [N] = getIntegers(input, " "); let A = getIntegers(input, " "); let B = getIntegers(input, " "); let C = new Array(N).fill(0); let min = Number.MAX_SAFE_INTEGER; for(let i=0; i<N; i++) { let queue = new PriorityQueue(function(a, b) { if(a.v == b.v) return a.p < b.p; return a.v < b.v; }); for(let j=0; j<N; j++) { let val = {v:A[j], p:0}; queue.push(val); } let now = solve(queue, B, i); min = Math.min(min, now); } console.log(min); } function solve(Q, B, i) { let j = i; let max = 0; while(true) { let enemy = B[i]; let now = Q.pop(); now.v += Math.floor(enemy / 2); now.p ++; max = Math.max(max, now.p); Q.push(now); i = (i+1) % B.length; if(i == j) break; } return max; } //-- functions --------------------------------------------------------------- function getIntegers(l, s) {return s === undefined ? l.map(x=>Number(x)) : l.shift().split(s).map(x=>Number(x))} const top = 0; const parent = i => ((i + 1) >>> 1) - 1; const left = i => (i << 1) + 1; const right = i => (i + 1) << 1; class PriorityQueue { constructor(comparator = (a, b) => a < b) { this._heap = []; this._comparator = comparator; } size() { return this._heap.length; } isEmpty() { return this.size() == 0; } peek() { return this._heap[top]; } push(...values) { values.forEach(value => { this._heap.push(value); this._siftUp(); }); return this.size(); } pop() { const poppedValue = this.peek(); const bottom = this.size() - 1; if (bottom > top) { this._swap(top, bottom); } this._heap.pop(); this._siftDown(); return poppedValue; } replace(value) { const replacedValue = this.peek(); this._heap[top] = value; this._siftDown(); return replacedValue; } _greater(i, j) { return this._comparator(this._heap[i], this._heap[j]); } _swap(i, j) { [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]]; } _siftUp() { let node = this.size() - 1; while (node > top && this._greater(node, parent(node))) { this._swap(node, parent(node)); node = parent(node); } } _siftDown() { let node = top; while ( (left(node) < this.size() && this._greater(left(node), node)) || (right(node) < this.size() && this._greater(right(node), node)) ) { let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node); this._swap(node, maxChild); node = maxChild; } } } main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));