結果
問題 | No.777 再帰的ケーキ |
ユーザー | ikd |
提出日時 | 2020-05-03 10:53:04 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 498 ms / 2,000 ms |
コード長 | 1,817 bytes |
コンパイル時間 | 4,209 ms |
コンパイル使用メモリ | 71,508 KB |
実行使用メモリ | 29,192 KB |
最終ジャッジ日時 | 2023-09-02 09:20:54 |
合計ジャッジ時間 | 9,262 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 1 ms
4,380 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 2 ms
4,380 KB |
testcase_19 | AC | 2 ms
4,376 KB |
testcase_20 | AC | 2 ms
4,380 KB |
testcase_21 | AC | 5 ms
4,376 KB |
testcase_22 | AC | 5 ms
4,380 KB |
testcase_23 | AC | 3 ms
4,380 KB |
testcase_24 | AC | 2 ms
4,376 KB |
testcase_25 | AC | 5 ms
4,380 KB |
testcase_26 | AC | 5 ms
4,380 KB |
testcase_27 | AC | 3 ms
4,376 KB |
testcase_28 | AC | 462 ms
28,160 KB |
testcase_29 | AC | 463 ms
28,568 KB |
testcase_30 | AC | 496 ms
28,120 KB |
testcase_31 | AC | 498 ms
28,272 KB |
testcase_32 | AC | 311 ms
29,192 KB |
testcase_33 | AC | 103 ms
13,556 KB |
testcase_34 | AC | 148 ms
17,172 KB |
testcase_35 | AC | 406 ms
21,936 KB |
testcase_36 | AC | 323 ms
28,016 KB |
ソースコード
import strutils, algorithm, sequtils, math, sugar type SegmentTree[T] = object n: int dat: seq[T] e: T multiply: proc(a, b: T): T proc initSegmentTree[T](n: int, e: T, f: proc(a, b: T): T): SegmentTree[T] = let nn = nextPowerOfTwo(n) var dat = newSeqWith(nn * 2 - 1, e) return SegmentTree[T](n: nn, dat: dat, e: e, multiply: f) proc get[T](this: SegmentTree[T], i: int): T = return this.dat[i + this.n - 1] proc update[T](this: var SegmentTree[T], i: int, x: T) = var k = i + this.n - 1 this.dat[k] = x while k > 0: k = (k - 1) div 2 this.dat[k] = this.multiply(this.dat[k * 2 + 1], this.dat[k * 2 + 2]) proc query[T](this: SegmentTree[T], ql, qr, i, il, ir: int): T = if ql <= il and ir <= qr: return this.dat[i] if qr <= il or ir <= ql: return this.e let m = (il + ir) div 2 return this.multiply( this.query(ql, qr, i * 2 + 1, il, m), this.query(ql, qr, i * 2 + 2, m, ir)) proc query[T](this: SegmentTree[T], ql, qr: int): T = return this.query(ql, qr, 0, 0, this.n) let read = iterator: string {.closure.} = while true: for s in stdin.readLine.split: yield s proc main() = let n = read().parseInt type P = tuple[a, b, c: int] var cakes = newSeq[P]() for i in 0..<n: let a, b, c = read().parseInt cakes.add((a, b, c)) var bs = newSeq[int]() for p in cakes: bs.add(p.b) bs.sort(cmp) bs = bs.deduplicate(isSorted = true) proc map(b: int): int = return bs.lowerBound(b) let m = bs.len var seg = initSegmentTree[int64]( m, 0.int64, proc(x, y: int64): int64 = max(x, y)) cakes.sort((p, q: P) => (if p.a == q.a: cmp(p.b, q.b) else: cmp(q.a, p.a))) for p in cakes: let i = map(p.b) let h = seg.query(i + 1, m) seg.update(i, max(seg.get(i), h + p.c)) echo seg.query(0, m) main()