結果

問題 No.755 Zero-Sum Rectangle
ユーザー むらためむらため
提出日時 2019-01-25 21:03:02
言語 Nim
(2.0.2)
結果
AC  
実行時間 1,791 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 2,677 ms
コンパイル使用メモリ 66,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 02:53:17
合計ジャッジ時間 23,382 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1,787 ms
4,380 KB
testcase_02 AC 1,488 ms
4,376 KB
testcase_03 AC 1,644 ms
4,376 KB
testcase_04 AC 1,707 ms
4,380 KB
testcase_05 AC 1,752 ms
4,380 KB
testcase_06 AC 1,497 ms
4,380 KB
testcase_07 AC 1,456 ms
4,376 KB
testcase_08 AC 1,617 ms
4,376 KB
testcase_09 AC 1,697 ms
4,380 KB
testcase_10 AC 1,791 ms
4,380 KB
testcase_11 AC 2 ms
4,376 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()
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 B = newSeqWith(m+1,newSeqWith(m+1,0))
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:
          B[ax][ay] += 1

n.times:
  let y = scan()
  let x = scan()
  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