結果

問題 No.489 株に挑戦
ユーザー むらためむらため
提出日時 2019-02-04 05:58:30
言語 Nim
(2.0.2)
結果
TLE  
実行時間 -
コード長 2,233 bytes
コンパイル時間 2,787 ms
コンパイル使用メモリ 69,852 KB
実行使用メモリ 22,464 KB
最終ジャッジ日時 2023-09-14 03:26:36
合計ジャッジ時間 6,790 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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)

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()
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 smax = initSegmentTree[int](n,-1e10.int,maximpl[int])
for i in 0..<n: smax[i] = S[i]
var ans = 0
var time = 0
for i in 0..<n:
  if i+d >= n : break
  let v = smax[i+1..i+d] - S[i]
  if v <= ans : continue
  ans = v
  time = i
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
    quit 0
0