結果

問題 No.755 Zero-Sum Rectangle
ユーザー pekempeypekempey
提出日時 2018-12-03 03:43:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 67,348 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 21:04:10
合計ジャッジ時間 9,269 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 22 ms
4,380 KB
testcase_02 AC 250 ms
4,380 KB
testcase_03 AC 355 ms
4,376 KB
testcase_04 AC 460 ms
4,376 KB
testcase_05 AC 478 ms
4,376 KB
testcase_06 AC 454 ms
4,380 KB
testcase_07 AC 377 ms
4,376 KB
testcase_08 AC 554 ms
4,380 KB
testcase_09 AC 473 ms
4,376 KB
testcase_10 AC 559 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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