結果
| 問題 |
No.777 再帰的ケーキ
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-12-24 10:19:56 |
| 言語 | Nim (2.2.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,333 bytes |
| コンパイル時間 | 3,877 ms |
| コンパイル使用メモリ | 72,532 KB |
| 実行使用メモリ | 37,984 KB |
| 最終ジャッジ日時 | 2024-07-01 06:13:36 |
| 合計ジャッジ時間 | 9,982 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 4 |
| other | WA * 5 RE * 28 |
ソースコード
import strutils, sequtils, algorithm, tables
type SegmentTree = object
n: int
dat: seq[int64]
proc init(sz: int): SegmentTree =
var n = 1
while n<sz: n*=2
var dat = newSeqWith(n*2-1, 0'i64)
result = SegmentTree(n: n, dat: dat)
proc update(this: var SegmentTree, i: int, x: int64) =
var k = i+this.n-1
if this.dat[k]<x:
this.dat[k] = x
while k>0:
k = (k-1) div 2
this.dat[k] = max(this.dat[k*2+1], this.dat[k*2+2])
proc rmax(this: SegmentTree, ql, qr, i, il, ir: int): int64 =
if qr<=il or ir<=ql:
result = 0
elif ql<=il and ir<=qr:
result = this.dat[i]
else:
let m = (il+ir) div 2
result = max(
this.rmax(ql, qr, i*2+1, il, m), this.rmax(ql, qr, i*2+2, m, ir))
proc main() =
let n = stdin.readLine.parseInt
var abcs = (0..<n).mapIt(stdin.readLine.split.map(parseInt))
abcs.sort(proc(x, y: seq[int]): int = cmp(x[1], y[1]))
var map = newTable[int64, int]()
for abc in abcs:
if not map.hasKey(abc[1]):
map[abc[1]] = map.len
abcs.sort do (x, y: seq[int])->int:
result = cmp(y[0], x[0])
if result==0:
result = cmp(y[1], x[1])
let m = map.len
var
tree = init(m)
ans = 0'i64
for i, abc in abcs:
let s = tree.rmax(0, map[abc[1]], 0, 0, tree.n) + abc[2]
ans = max(ans, s)
tree.update(abc[1], s)
echo ans
main()
ikd