結果

問題 No.489 株に挑戦
ユーザー むらためむらため
提出日時 2019-02-04 07:08:44
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 3,428 bytes
コンパイル時間 3,146 ms
コンパイル使用メモリ 78,220 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-07-01 11:20:20
合計ジャッジ時間 4,734 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,812 KB
testcase_01 RE -
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 5 ms
6,940 KB
testcase_19 RE -
testcase_20 AC 9 ms
6,948 KB
testcase_21 RE -
testcase_22 AC 2 ms
6,948 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 8 ms
6,948 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 WA -
testcase_30 RE -
testcase_31 AC 8 ms
6,940 KB
testcase_32 AC 6 ms
6,940 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 5 ms
6,940 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,math,times,deques
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)
template stopwatch(body) = (let t1 = cpuTime();body;echo "TIME:",(cpuTime() - t1) * 1000,"ms")

template useSegmentTree() = # 区間[s,t)の最小(最大)値 / 更新 O(log(N))
  proc minimpl[T](x,y:T): T = (if x <= y: x else: y)
  proc maximpl[T](x,y:T): T = (if x >= y: x else: y)
  type SegmentTree[T] = object
    data:seq[T] # import math
    n : int
    rawSize:int
    infinity: T
    cmp:proc(x,y:T):T
  proc initSegmentTree[T](
      size:int,
      infinity:T = T(1e10),
      cmp: proc (x,y:T):T = minimpl[T]) : SegmentTree[T] =
    result.infinity = infinity
    result.cmp = cmp
    result.n = size.nextPowerOfTwo()
    result.rawSize = size
    result.data = newSeqWith(result.n * 2,result.infinity)
  proc `[]=`[T](self:var SegmentTree[T],i:int,val:T) =
    var i = i + self.n - 1
    self.data[i] = val
    while i > 0:
      i = (i - 1) shr 1
      self.data[i] = self.cmp(self.data[i * 2 + 1],self.data[i * 2 + 2])
  proc `[]`[T](self:SegmentTree[T],slice:Slice[int]): T =
    proc impl(a,b,k,l,r:int):T =
      if r <= a or b <= l : return self.infinity
      if a <= l and r <= b : return self.data[k]
      let vl = impl(a,b,k*2+1,l,(l+r) shr 1)
      let vr = impl(a,b,k*2+2,(l+r) shr 1,r)
      return self.cmp(vl,vr)
    return impl(slice.a,slice.b+1,0,0,self.n)

  proc `$`[T](self:SegmentTree[T]): string =
    var arrs : seq[seq[int]] = @[]
    var l = 0
    var r = 1
    while r <= self.data.len:
      arrs &= self.data[l..<r]
      l = l * 2 + 1
      r = r * 2 + 1
    return $arrs

# useSegmentTree()

template useSlideMin = # ?
  proc minimpl[T](x,y:T): T = (if x <= y: x else: y)
  proc maximpl[T](x,y:T): T = (if x >= y: x else: y)
  type SlideMin[T] = ref object
    deq:seq[int]
    vals:seq[T]
    l,r:int
    width:int
    len:int
    infinity: T
    cmp:proc(x,y:T):T

  proc initSlideMin[T](
      width:int,
      cmp: proc (x,y:T):T = minimpl[T]) : SlideMin[T] =
    new(result)
    result.deq = newSeq[int]()
    result.vals = newSeq[T]()
    result.width = width + 1
    result.cmp = cmp
  proc `&=`[T](self:SlideMin,val:T): T = # (自分を含む)過去width個での最小値を返す
    self.vals &= val
    while self.l < self.r and val == self.cmp(val,self.vals[self.deq[self.r-1]]):
      self.r -= 1
    if self.deq.len > self.r : self.deq[self.r] = self.len
    else: self.deq &= self.len
    self.r += 1
    self.len += 1
    if self.len - self.width >= 0 :
      if self.deq[self.l] == self.len - self.width:
        self.l += 1
    return self.vals[self.deq[self.l]]
useSlideMin()

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord
let n = scan()
let d = scan()
let k = scan()
let S = newSeqWith(n,scan())
var slide = initSlideMin[int](d,maximpl)
var ans = 0
var time = 0
var maxVal = 0
for i in 0..<n:
  maxVal = (slide &= S[i])
  if i < d : continue
  let v = maxVal - S[i-d]
  if v <= ans : continue
  ans = v
  time = i-d
for i in n-d..<n:
  let v = maxVal - S[i]
  if v <= ans : continue
  ans = v
  time = i-d

if ans <= 0 : quit "0",0
echo ans * k
stdout.write time," "
for i in time+1..<n:
  if S[i] == ans + S[time] :
    echo i
    break
0