結果

問題 No.755 Zero-Sum Rectangle
ユーザー 0w10w1
提出日時 2018-12-10 01:36:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,161 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 207,804 KB
実行使用メモリ 7,700 KB
最終ジャッジ日時 2023-10-14 22:01:28
合計ジャッジ時間 21,298 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,700 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 AC 2 ms
4,356 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

signed main() {
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  vector<vector<int>> A(M, vector<int>(M));
  for (int i = 0; i < M; ++i)
    for (int j = 0; j < M; ++j)
      cin >> A[i][j];

  vector<vector<int64_t>> sum(M, vector<int64_t>(M));
  for (int i = 0; i < M; ++i)
    for (int j = 0; j < M; ++j) {
      sum[i][j] = A[i][j];
      if (i) sum[i][j] += sum[i - 1][j];
      if (j) sum[i][j] += sum[i][j - 1];
      if (i && j) sum[i][j] -= sum[i - 1][j - 1];
    }

  auto query = [&](int r1, int c1, int r2, int c2) {
    int64_t res = sum[r2][c2];
    if (r1) res -= sum[r1 - 1][c2];
    if (c1) res -= sum[r2][c1 - 1];
    if (r1 && c1) res += sum[r1 - 1][c1 - 1];
    return res;
  };

  for (int i = 0; i < N; ++i) {
    int X, Y;
    cin >> X >> Y;
    --X, --Y;
    int ans = 0;
    for (int r1 = 0; r1 < M; ++r1)
      for (int c1 = 0; c1 < M; ++c1)
        for (int r2 = 0; r2 < M; ++r2)
          for (int c2 = 0; c2 < M; ++c2)
            if (r1 <= X && X <= r2 && c1 <= Y && Y <= c2)
              ans += query(r1, c1, r2, c2) == 0;
    cout << ans << endl;
  }

  return 0;
}
0