結果

問題 No.33 アメーバがたくさん
ユーザー むらためむらため
提出日時 2018-12-16 03:16:45
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,044 bytes
コンパイル時間 3,286 ms
コンパイル使用メモリ 72,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 21:23:48
合計ジャッジ時間 4,092 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 45) Warning: imported and not used: 'math' [UnusedImport]
/home/judge/data/code/Main.nim(1, 50) Warning: imported and not used: 'sugar' [UnusedImport]
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'strscans' [UnusedImport]
/home/judge/data/code/Main.nim(1, 35) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,sugar,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[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