結果

問題 No.755 Zero-Sum Rectangle
ユーザー むらためむらため
提出日時 2019-01-25 20:23:32
言語 Nim
(2.0.2)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,142 bytes
コンパイル時間 2,999 ms
コンパイル使用メモリ 66,428 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 02:51:50
合計ジャッジ時間 25,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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()
let A = newSeqWith(m,newSeqWith(m,scan()))
var C = newSeqWith(m,newSeq[int](m))
block:
  C[0][0] = A[0][0]
  for x in 1..<m: C[x][0] = C[x-1][0] + A[x][0]
  for y in 1..<m: C[0][y] = C[0][y-1] + A[0][y]
  for x in 1..<m:
    for y in 1..<m:
      C[x][y] = C[x-1][y] + C[x][y-1] - C[x-1][y-1] + A[x][y]
proc calcSum(ax,ay,bx,by:int):int =
  let a = if ax != 0 : C[ax-1][by] else: 0
  let b = if ay != 0 : C[bx][ay-1] else: 0
  let c = if ax != 0 and ay != 0: C[ax-1][ay-1] else: 0
  return C[bx][by] - b - a + c

n.times:
  let x = scan() - 1
  let y = scan() - 1
  var ans = 0
  for ax in 0..x:
    for ay in 0..y:
      for bx in x..<m:
        for by in y..<m:
          if calcSum(ax,ay,bx,by) == 0:
            ans += 1
  echo ans
0