結果

問題 No.60 魔法少女
ユーザー むらためむらため
提出日時 2017-08-16 11:05:15
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,876 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 66,836 KB
最終ジャッジ日時 2024-04-27 02:29:19
合計ジャッジ時間 1,430 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 41) 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(43, 38) 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,algorithm,math,future,macros
template get*():string = stdin.readLine() #.strip()
macro unpack*(arr: auto,cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `arr`;())
  for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`])
template times*(n:int,body:untyped): untyped = (for _ in 0..<n: body)

proc getc(file:File):char {. importc:"getc",header: "<stdio.h>" .}
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan1[T](): T =
  var minus = false
  result = 0
  while true:
    var k = stdin.getc()
    #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
macro scanints(cnt:static[int]): auto =
  result = nnkBracket.newNimNode
  for i in 0..<cnt: result.add(quote do: scan1[int]())

# N,K<1e6  |X,Y|,W,H<=500  HP,D<1e5 | [X,X+W] [Y,Y+W] に D | 倒れていない敵の体力の合計

template imosReduce2(field:typed):void =
  for x in field.low + 1 .. field.high:
    for y in field[x].low .. field[x].high:
      field[x][y] += field[x-1][y]
  for x in field.low .. field.high:
    for y in field[x].low + 1 .. field[x].high:
      field[x][y] += field[x][y-1]

template imosRegist2(field:typed,x1,y1,x2,y2:int,val:typed):void =
  field[x1][y1] += val
  field[x1][y2+1] -= val
  field[x2+1][y1] -= val
  field[x2+1][y2+1] += val


var field : array[-501..501,array[-501..501,int]]
let
  (N,K) = get().split().map(parseInt).unpack(2)
  ene_XYHP = newSeqWith(N,scanints(3))
  my_XYWHD = newSeqWith(K,scanints(5))
for xywhd in my_XYWHD:
   let (x,y,w,h,d) = xywhd.unpack(5)
   field.imosRegist2(x,y,min(500,x+w),min(500,y+h),d)
field.imosReduce2()
var damageSum = 0
for n in 0..<N:
  let (x,y,hp) = ene_XYHP[n].unpack(3)
  damageSum += 0.max(hp-field[x][y])
echo damageSum
0