結果
| 問題 | No.755 Zero-Sum Rectangle | 
| コンテスト | |
| ユーザー |  iqueue02 | 
| 提出日時 | 2020-02-16 11:29:34 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 121 ms / 2,000 ms | 
| コード長 | 850 bytes | 
| コンパイル時間 | 1,879 ms | 
| コンパイル使用メモリ | 175,756 KB | 
| 実行使用メモリ | 13,640 KB | 
| 最終ジャッジ日時 | 2024-10-06 14:24:09 | 
| 合計ジャッジ時間 | 6,141 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 11 TLE * 1 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(m, vector<int>(m));
  vector<vector<ll>> d_cum(m+1, vector<ll>(m,0));
  rep(i,m) rep(j,m) cin >> a[i][j], d_cum[i+1][j+1] = a[i][j];
  rep(i,m) rep(j,m) d_cum[i+1][j+1] += d_cum[i+1][j] + d_cum[i][j+1] - d_cum[i][j];
  while (n--) {
    int x, y;
    cin >> x >> y;
    int res = 0;
    for (int a = 0; a < x; a++) {
      for (int b = 0; b < y; b++) {
        for (int c = x; c <= m; c++) {
          for (int d = y; d <= m; d++) {
            ll sum = d_cum[c][d] - d_cum[a][d] - d_cum[c][b] + d_cum[a][b];
            if (!sum) res++;
          }
        }
      }
    }
    cout << res << endl;
  } 
  return 0;
}
            
            
            
        