結果

問題 No.755 Zero-Sum Rectangle
コンテスト
ユーザー pekempey
提出日時 2018-12-03 03:43:21
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 350 ms / 2,000 ms
コード長 840 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 715 ms
コンパイル使用メモリ 85,172 KB
実行使用メモリ 11,424 KB
最終ジャッジ日時 2026-03-22 00:04:11
合計ジャッジ時間 8,700 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <map>

using namespace std;

int n, m;
long long a[130][130];
long long S[131][131];

long long f(int y1, int y2, int x1, int x2) {
  return S[y2][x2] - S[y2][x1] - S[y1][x2] + S[y1][x1];
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      S[i + 1][j + 1] = S[i + 1][j] + S[i][j + 1] - S[i][j] + a[i][j];
    }
  }
  while (n--) {
    int y, x;
    cin >> y >> x;
    y--; x--;
    long long ans = 0;
    for (int a = 0; a <= y; a++) {
      for (int b = y + 1; b <= m; b++) {
        map<long long, int> mp;
        for (int c = 0; c <= x; c++) {
          mp[f(a, b, c, x)]++;
        }
        for (int c = x + 1; c <= m; c++) {
          ans += mp[-f(a, b, x, c)];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
0