結果

問題 No.755 Zero-Sum Rectangle
ユーザー むらためむらため
提出日時 2019-01-25 20:57:22
言語 Nim
(2.0.2)
結果
MLE  
実行時間 -
コード長 1,278 bytes
コンパイル時間 2,586 ms
コンパイル使用メモリ 67,420 KB
実行使用メモリ 813,812 KB
最終ジャッジ日時 2023-09-14 02:51:03
合計ジャッジ時間 5,127 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
evil_1 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils
template times*(n:int,body) = (for _ in 0..<n: body)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  var minus = false
  while true:
    let 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

let n = scan()
let m = scan()
var A = newSeqWith(m+1,newSeqWith(m+1,0))
for y in 1..m:
  for x in 1..m:
    A[x][y] = scan() + A[x-1][y] + A[x][y-1] - A[x-1][y-1]

proc calcSum(ax,ay,bx,by:int):int = A[bx][by] - A[bx][ay] - A[ax][by] + A[ax][ay]

var sumIsZeros = newSeq[tuple[ax,ay,bx,by:int]]()
for ax in 0..<m:
  for ay in 0..<m:
    for bx in (ax+1)..m:
      for by in (ay+1)..m:
        if calcSum(ax,ay,bx,by) == 0:
          sumIsZeros &= (ax,ay,bx,by)

n.times:
  let y = scan()
  let x = scan()
  var ans = 0
  for s in sumIsZeros:
    let (ax,ay,bx,by) = s
    if ax < x and x <= bx and ay < y and y <= by : ans += 1
  echo ans
  # var ans = 0
  # for ax in 0..<x:
  #   for ay in 0..<y:
  #     let axay = A[ax][ay]
  #     for bx in x..m:
  #       let bxay = A[bx][ay]
  #       for by in y..m:
  #         if A[bx][by] - A[ax][by] - bxay + axay == 0:
  #           ans += 1
  # echo ans
0