結果

問題 No.755 Zero-Sum Rectangle
ユーザー simansiman
提出日時 2022-06-28 13:12:08
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,669 bytes
コンパイル時間 5,336 ms
コンパイル使用メモリ 104,552 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-13 10:53:32
合計ジャッジ時間 36,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 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 WA -
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  ll A[M][M];

  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> A[i][j];
    }
  }
  ll S[M + 1][M + 1];
  memset(S, 0, sizeof(S));
  for (int y = 1; y <= M; ++y) {
    for (int x = 1; x <= M; ++x) {
      S[y][x] = S[y][x - 1] + A[y - 1][x - 1];
    }
  }
  for (int x = 0; x <= M; ++x) {
    for (int y = 1; y <= M; ++y) {
      S[y][x] += S[y - 1][x];
    }
  }

  /*
  for (int y = 0; y <= M; ++y) {
    for (int x = 0; x <= M; ++x) {
      cerr << S[y][x] << " ";
    }
    cerr << endl;
  }
  */

  int x, y;
  for (int i = 0; i < N; ++i) {
    cin >> y >> x;
    int ans = 0;

    for (int cy = 1; cy <= M; ++cy) {
      for (int cx = 1; cx <= M; ++cx) {
        int cz = cy * M + cx;

        for (int ny = 1; ny <= M; ++ny) {
          for (int nx = 1; nx <= M; ++nx) {
            if (ny < cy) continue;
            if (nx < cx) continue;

            int ly = min(cy, ny);
            int lx = min(cx, nx);
            int ry = max(cy, ny);
            int rx = max(cx, nx);

            if (ly <= y && y <= ry && lx <= x && x <= rx) {
              int sum = S[ry][rx] - S[ry][lx - 1] - S[ly - 1][rx] + S[ly - 1][lx - 1];
              // fprintf(stderr, "(%d, %d) -> (%d, %d) sum: %d\n", lx, ly, rx, ry, sum);
              if (sum == 0) ++ans;
            }
          }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}
0