結果

問題 No.755 Zero-Sum Rectangle
ユーザー むらためむらため
提出日時 2019-01-25 20:46:34
言語 Nim
(2.0.2)
結果
AC  
実行時間 867 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 2,435 ms
コンパイル使用メモリ 66,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 02:49:46
合計ジャッジ時間 14,035 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 652 ms
4,376 KB
testcase_02 AC 492 ms
4,376 KB
testcase_03 AC 689 ms
4,376 KB
testcase_04 AC 773 ms
4,380 KB
testcase_05 AC 825 ms
4,376 KB
testcase_06 AC 532 ms
4,380 KB
testcase_07 AC 506 ms
4,380 KB
testcase_08 AC 672 ms
4,376 KB
testcase_09 AC 765 ms
4,376 KB
testcase_10 AC 867 ms
4,376 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()
for x in 1..m:
  for y in 1..m:
    A[x][y] = A[x-1][y] + A[x][y-1] - A[x-1][y-1] + A[x][y]

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

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