結果
| 問題 |
No.580 旅館の予約計画
|
| ユーザー |
|
| 提出日時 | 2019-01-25 14:53:34 |
| 言語 | Nim (2.2.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,625 bytes |
| コンパイル時間 | 2,639 ms |
| コンパイル使用メモリ | 62,164 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-01 10:45:40 |
| 合計ジャッジ時間 | 3,700 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 27) Warning: imported and not used: 'sugar' [UnusedImport]
ソースコード
import sequtils,algorithm,sugar
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
while true:
let k = getchar_unlocked()
if k < '0' or k > '9': break
result = 10 * result + k.ord - '0'.ord
template useBinaryHeap() =
type
BinaryHeap*[T] = object
nodes: seq[T]
compare: proc(x,y:T):int
popchunk: bool
proc newBinaryHeap*[T](compare:proc(x,y:T):int): BinaryHeap[T] =
BinaryHeap[T](nodes:newSeq[T](),compare:compare,popchunk:false)
proc compareNode[T](h:BinaryHeap[T],i,j:int):int = h.compare(h.nodes[i],h.nodes[j])
proc size*[T](h:BinaryHeap[T]):int = h.nodes.len() - h.popchunk.int
proc items*[T](h:var BinaryHeap[T]):seq[T] =
if h.popchunk : discard h.popimpl()
return h.nodes
proc top*[T](h:var BinaryHeap[T]): T =
if h.popchunk : discard h.popimpl()
return h.nodes[0]
proc push*[T](h:var BinaryHeap[T],node:T):void =
if h.popchunk :
h.nodes[0] = node
h.shiftdown()
else: h.pushimpl(node)
proc pop*[T](h:var BinaryHeap[T]):T =
if h.popchunk: discard h.popimpl()
h.popchunk = true
return h.nodes[0]
proc shiftdown[T](h:var BinaryHeap[T]): void =
h.popchunk = false
let size = h.nodes.len()
var i = 0
while true :
let L = i * 2 + 1
let R = i * 2 + 2
if L >= size : break
let child = if R < size and h.compareNode(R,L) <= 0 : R else: L
if h.compareNode(i,child) <= 0: break
swap(h.nodes[i],h.nodes[child])
i = child
proc pushimpl[T](h:var BinaryHeap[T],node:T):void =
h.nodes.add(node) #末尾に追加
var i = h.nodes.len() - 1
while i > 0: # 末尾から木を整形
let parent = (i - 1) div 2
if h.compare(h.nodes[parent],node) <= 0: break
h.nodes[i] = h.nodes[parent]
i = parent
h.nodes[i] = node
proc popimpl[T](h:var BinaryHeap[T]):T =
result = h.nodes[0] # rootと末尾を入れ替えて木を整形
h.nodes[0] = h.nodes[^1]
h.nodes.setLen(h.nodes.len() - 1)
h.shiftdown()
useBinaryHeap()
proc parseLine(): tuple[x,y:int] =
result.x = scan() * 1440 + scan() * 60 + scan()
result.y = scan() * 1440 + scan() * 60 + scan()
let n = scan()
let m = scan()
let U = newSeqWith(m,parseLine()).sortedByIt(it.y)
# var pq = newBinaryHeap[tuple[a,b:int]]((x,y)=> (
# if x.b != y.b: y.b - x.b else:
# ))
# for i in 0..<n:pq.push(0)
var preY = newSeq[int](n)
var ans = 0
for u in U:
for i in 0..<n: # preYの遅い順に見るべき
if preY[i] >= u.x: continue
preY[i] = u.y
ans += 1
preY.sort(cmp,Descending)
break
echo ans