結果
問題 | No.318 学学学学学 |
ユーザー | t8m8⛄️ |
提出日時 | 2017-06-09 15:46:37 |
言語 | Nim (2.0.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,436 bytes |
コンパイル時間 | 4,026 ms |
コンパイル使用メモリ | 70,188 KB |
実行使用メモリ | 25,692 KB |
最終ジャッジ日時 | 2023-09-12 12:56:18 |
合計ジャッジ時間 | 19,959 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
4,812 KB |
testcase_01 | AC | 11 ms
6,308 KB |
testcase_02 | AC | 13 ms
6,496 KB |
testcase_03 | AC | 10 ms
6,028 KB |
testcase_04 | AC | 11 ms
6,448 KB |
testcase_05 | AC | 68 ms
25,484 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1,611 ms
18,048 KB |
testcase_08 | AC | 1,792 ms
15,452 KB |
testcase_09 | AC | 1,860 ms
15,568 KB |
testcase_10 | AC | 1,901 ms
15,392 KB |
testcase_11 | AC | 65 ms
25,692 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 58 ms
14,632 KB |
testcase_17 | WA | - |
testcase_18 | AC | 56 ms
19,632 KB |
testcase_19 | TLE | - |
testcase_20 | WA | - |
testcase_21 | AC | 2 ms
4,376 KB |
testcase_22 | AC | 2 ms
4,380 KB |
testcase_23 | AC | 2 ms
4,376 KB |
testcase_24 | AC | 2 ms
4,380 KB |
testcase_25 | AC | 2 ms
4,376 KB |
testcase_26 | AC | 1 ms
4,376 KB |
testcase_27 | AC | 2 ms
4,380 KB |
testcase_28 | AC | 1 ms
4,380 KB |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 39) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
ソースコード
import strutils, sequtils, algorithm, future, tables type PrirorityQueue*[T] = ref object of RootObj elms: seq[T] cmp: (T, T) -> int proc newPriorityQueue*[T](cmp: (T, T) -> int): PrirorityQueue[T] = new(result) result.elms = newSeq[T]() result.cmp = cmp template parent(cur: int): int = (cur - 1) div 2 template childl(cur: int): int = cur * 2 + 1 template childr(cur: int): int = cur * 2 + 2 proc upHeap[T](self: var PrirorityQueue[T], cur: var int) = var par = parent(cur) while par >= 0 and self.cmp(self.elms[cur], self.elms[par]) < 0: swap(self.elms[cur], self.elms[par]) (cur, par) = (par, parent(par)) proc downHeap[T](self: var PrirorityQueue[T], cur: var int) = var (chl, chr) = (childl(cur), childr(cur)) while chl < self.elms.len: var ch = if chr >= self.elms.len or self.cmp(self.elms[chl], self.elms[chr]) < 0: chl else: chr if self.cmp(self.elms[cur], self.elms[ch]) < 0: break swap(self.elms[cur], self.elms[ch]) (cur, chl, chr) = (ch, childl(cur), childr(cur)) proc len*[T](self: PrirorityQueue[T]): int = self.elms.len proc peek*[T](self: var PrirorityQueue[T]): T = self.elms[0] proc push*[T](self: var PrirorityQueue[T], data: T) = var n = self.elms.len cur = n self.elms.setLen(n + 1) self.elms[cur] = data self.upHeap(cur) proc pop*[T](self: var PrirorityQueue[T]): T = assert self.elms.len > 0 var n = self.elms.len cur = 0 result = self.elms[0] self.elms[cur] = self.elms[n-1] self.elms.del(n-1) self.downHeap(cur) proc delete*[T](self: var PrirorityQueue[T], data: T): bool = var n = self.elms.len idx = -1 for i in 0..<n: if self.elms[i] == data: idx = i break if idx == -1: return false elif idx == n - 1: self.elms.del(idx) else: self.elms[idx] = self.elms[n-1] self.elms.del(n-1) self.downHeap(idx) self.upHeap(idx) return true # ============================================================================== when isMainModule: var n = stdin.readLine.parseInt a = stdin.readLine.split.map(parseInt) b = newSeq[int](n) lastIdx = newTable[int, int]() pQ = newPriorityQueue[int]((x: int, y: int) => y - x) for i in 0..<n: lastIdx[a[i]] = i for i in 0..<n: pQ.push(a[i]) b[i] = pQ.peek() if i == lastIdx[a[i]]: while pQ.delete(a[i]): discard echo b.join(" ")