結果

問題 No.755 Zero-Sum Rectangle
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-03-27 13:56:48
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 2,374 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 107,316 KB
実行使用メモリ 7,012 KB
最終ジャッジ日時 2023-09-04 06:28:51
合計ジャッジ時間 7,487 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 111 ms
4,380 KB
testcase_02 AC 182 ms
4,380 KB
testcase_03 AC 262 ms
4,376 KB
testcase_04 AC 280 ms
4,380 KB
testcase_05 AC 264 ms
6,356 KB
testcase_06 AC 231 ms
6,708 KB
testcase_07 AC 241 ms
7,012 KB
testcase_08 AC 373 ms
6,708 KB
testcase_09 AC 287 ms
6,416 KB
testcase_10 AC 299 ms
6,684 KB
testcase_11 AC 2 ms
4,380 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const Q = readInt();
      const M = readInt();
      auto A = new long[][](M, M);
      foreach (x; 0 .. M) foreach (y; 0 .. M) {
        A[x][y] = readLong();
      }
      auto X = new int[Q];
      auto Y = new int[Q];
      foreach (q; 0 .. Q) {
        X[q] = readInt() - 1;
        Y[q] = readInt() - 1;
      }
      
      auto sum = new long[][](M + 1, M + 1);
      foreach (x; 0 .. M) foreach (y; 0 .. M) {
        sum[x + 1][y + 1] = sum[x + 1][y] + sum[x][y + 1] - sum[x][y] + A[x][y];
      }
      
      foreach (q; 0 .. Q) {
        long ans;
        foreach (xa; 0 .. X[q] + 1) foreach (xb; X[q] + 1 .. M + 1) {
          debug {
            writeln(xa, " ", xb, ": ", iota(M + 1).map!(y => (sum[xb][y] - sum[xa][y])));
          }
          long[long] freq;
          foreach (y; 0 .. Y[q] + 1) {
            const s = sum[xb][y] - sum[xa][y];
            ++freq[s];
          }
          foreach (y; Y[q] + 1 .. M + 1) {
            const s = sum[xb][y] - sum[xa][y];
            if (s in freq) {
              ans += freq[s];
            }
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}
0