結果

問題 No.755 Zero-Sum Rectangle
ユーザー iqueue02iqueue02
提出日時 2020-02-16 11:29:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 171,504 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-16 03:31:41
合計ジャッジ時間 6,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 93 ms
5,376 KB
testcase_02 AC 75 ms
5,376 KB
testcase_03 AC 100 ms
5,376 KB
testcase_04 AC 115 ms
5,376 KB
testcase_05 AC 126 ms
5,376 KB
testcase_06 AC 82 ms
5,376 KB
testcase_07 AC 76 ms
5,376 KB
testcase_08 AC 104 ms
5,376 KB
testcase_09 AC 119 ms
5,376 KB
testcase_10 AC 134 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0