結果

問題 No.33 アメーバがたくさん
ユーザー むらためむらため
提出日時 2017-08-14 00:54:43
言語 Nim
(2.0.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,048 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 57,804 KB
最終ジャッジ日時 2023-09-12 14:28:18
合計ジャッジ時間 1,142 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
stack trace: (most recent call last)
Main.nim(5, 7)           unpack
/home/judge/data/code/Main.nim(8, 40) template/generic instantiation of `unpack` from here
/home/judge/data/code/Main.nim(5, 7) Error: index 1 not in 0 .. 0

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,macros
template get*():string = stdin.readLine() #.strip()
macro unpack*(rhs: seq,cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `rhs`;())
  for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`])
let
  # N<100, D<10^9, T<10^9
  (N,D,T) = get().split().map(parseInt).unpack(3)
  X = get().split().map(parseInt)
  XLR = X.mapIt((L:it-D*T,M:it,R:it+D*T))
var ans = 0
for i,x in XLR:
  # other ameba range
  var amebas = newSeq[tuple[L,R:int]]()
  for y in XLR[0..<i]:
    if abs(x.M - y.M) mod D == 0 and
      (x.R >= y.L and y.R >= x.L) :
      amebas &= (max(y.L,x.L), min(y.R,x.R))
  # flatten
  const invalid = (1,-1)
  for ai,a in amebas:
    for bi,b in amebas[0..<ai]:
      if a.R >= b.L and b.R >= a.L and b != invalid:
        amebas[ai] = (min(a.L,b.L), max(a.R,b.R))
        amebas[bi] = invalid
  amebas = amebas.filterIt(it != invalid)
  # sub other ranges
  var seg = 2 * T + 1
  for a in amebas:
    seg -= (a.R - a.L) div D + 1
  ans += seg
echo ans
0