結果

問題 No.755 Zero-Sum Rectangle
ユーザー ei1333333ei1333333
提出日時 2018-12-03 00:07:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,616 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 204,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 20:59:55
合計ジャッジ時間 3,791 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 161 ms
4,380 KB
testcase_02 AC 97 ms
4,376 KB
testcase_03 AC 88 ms
4,380 KB
testcase_04 AC 82 ms
4,380 KB
testcase_05 AC 77 ms
4,376 KB
testcase_06 AC 75 ms
4,376 KB
testcase_07 AC 74 ms
4,376 KB
testcase_08 AC 75 ms
4,376 KB
testcase_09 AC 76 ms
4,380 KB
testcase_10 AC 77 ms
4,380 KB
testcase_11 WA -
evil_1 AC 100 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using int64 = long long;

template< class T >
struct CumulativeSum2D {
  vector< vector< T > > data;

  CumulativeSum2D(int W, int H) : data(W + 1, vector< int >(H + 1, 0)) {}

  void add(int x, int y, int z) {
    ++x, ++y;
    if(x >= data.size() || y >= data[0].size()) return;
    data[x][y] += z;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      for(int j = 1; j < data[i].size(); j++) {
        data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
      }
    }
  }

  T query(int sx, int sy, int gx, int gy) {
    return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
  }
};

int main() {
  int N, M;
  int A[130][130];

  cin >> N >> M;
  CumulativeSum2D< int > sum(M, M);
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < M; j++) {
      cin >> A[i][j];
      sum.add(j, i, A[i][j]);
    }
  }
  sum.build();


  int add[131][131] = {{}};
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < M; j++) {
      for(int k = i + 1; k <= M; k++) {
        for(int l = j + 1; l <= M; l++) {
          if(sum.query(i, j, k, l) == 0) {
            add[i][j]++;
            add[i][l]--;
            add[k][j]--;
            add[k][l]++;
          }
        }
      }
    }
  }

  for(int i = 0; i <= M; i++) {
    for(int j = 1; j <= M; j++) {
      add[i][j] += add[i][j - 1];
    }
  }
  for(int i = 1; i <= M; i++) {
    for(int j = 0; j <= M; j++) {
      add[i][j] += add[i - 1][j];
    }
  }

  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    cout << add[y][x] << endl;
  }

}
0