結果
| 問題 |
No.59 鉄道の旅
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-30 16:52:02 |
| 言語 | Nim (2.2.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 1,562 bytes |
| コンパイル時間 | 3,610 ms |
| コンパイル使用メモリ | 61,564 KB |
| 実行使用メモリ | 10,868 KB |
| 最終ジャッジ日時 | 2024-10-03 05:21:52 |
| 合計ジャッジ時間 | 3,745 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport] /home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'math' [UnusedImport]
ソースコード
import sequtils,math
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
result = 0
var minus = false
while true:
var k = getchar_unlocked()
if k == '-' : minus = true
elif k < '0' or k > '9': break
else: result = 10 * result + k.ord - '0'.ord
if minus: result *= -1
type BinaryIndexedTree[T] = ref object
data: seq[T] # 引数以下の部分和(Fenwick Tree)
proc initBinaryIndexedTree[T](n:int):BinaryIndexedTree[T] =
new(result)
result.data = newSeq[T](n)
proc len[T](self:BinaryIndexedTree[T]): int = self.data.len()
proc update[T](self:var BinaryIndexedTree[T],i:int,val:T) =
var i = i
while i < self.len():
self.data[i] += val
i = i or (i + 1)
proc `[]`[T](self:BinaryIndexedTree[T],i:int): T =
var i = i
while i >= 0:
result += self.data[i]
i = (i and (i + 1)) - 1
proc `$`[T](self:BinaryIndexedTree[T]): string =
result = "["
for i in 0..<self.len.min(100): result &= $(self[i]) & ", "
return result[0..result.len()-2] & (if self.len > 100 : " ...]" else: "]")
var last = 0
let n = scan()
let k = scan()
var cargo = initBinaryIndexedTree[int](100_0001)
n.times:
let w = scan()
if w > 0:
if last - cargo[w-1] >= k: continue # W以上の荷物がK個以上
cargo.update w, 1
last += 1
else:
if cargo[-w-1] == cargo[-w] : continue # 荷物が無い
cargo.update -w,-1
last -= 1
echo last