結果

問題 No.60 魔法少女
ユーザー むらためむらため
提出日時 2019-01-17 06:30:55
言語 Nim
(2.0.2)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 1,753 bytes
コンパイル時間 2,549 ms
コンパイル使用メモリ 66,224 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-09-13 22:37:44
合計ジャッジ時間 4,526 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,876 KB
testcase_01 AC 14 ms
6,852 KB
testcase_02 AC 14 ms
6,924 KB
testcase_03 AC 14 ms
7,028 KB
testcase_04 AC 27 ms
7,224 KB
testcase_05 AC 29 ms
7,916 KB
testcase_06 AC 38 ms
7,988 KB
testcase_07 AC 31 ms
7,688 KB
testcase_08 AC 26 ms
7,460 KB
testcase_09 AC 19 ms
7,268 KB
testcase_10 AC 37 ms
7,988 KB
testcase_11 AC 17 ms
7,156 KB
testcase_12 AC 24 ms
7,728 KB
testcase_13 AC 38 ms
8,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'strutils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 41) Warning: imported and not used: 'sugar' [UnusedImport]
/home/judge/data/code/Main.nim(1, 36) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,algorithm,math,sugar,macros
template get*():string = stdin.readLine() #.strip()
macro unpack*(arr: auto,cnt: static[int32]): 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:int32,body:untyped): untyped = (for _ in 0..<n: body)

template useScan =
  proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
  proc scan(): int32 =
    result = 0
    var minus = false
    while true:
      var k = getchar_unlocked()
      if k == '-' : minus = true
      elif k < '0' or k > '9': break
      else: result = 10.int32 * result + k.ord.int32 - '0'.ord.int32
    if minus: result *= -1

useScan()

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

template imosReduce2(field:typed) =
  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:int32,val:typed) =
  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,int32]]
let n = scan()
let k = scan()
var xyh : array[30_0002,int32]
for i in 0..<n:
  xyh[3*i+0] = scan()
  xyh[3*i+1] = scan()
  xyh[3*i+2] = scan()
k.times:
  let (x,y,w,h,d) = (scan(),scan(),scan(),scan(),scan())
  field.imosRegist2(x,y,min(500,x+w),min(500,y+h),d)
field.imosReduce2()
var damageSum = 0
for i in 0..<n:
  let (x,y,hp) = (xyh[3*i+0],xyh[3*i+1],xyh[3*i+2])
  damageSum += max(0, hp - field[x][y])
echo damageSum
0