結果

問題 No.755 Zero-Sum Rectangle
ユーザー kk
提出日時 2020-09-08 18:24:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 2,231 ms
コンパイル使用メモリ 215,568 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-20 03:08:44
合計ジャッジ時間 9,803 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 61 ms
4,380 KB
testcase_02 AC 174 ms
4,376 KB
testcase_03 AC 254 ms
4,384 KB
testcase_04 AC 338 ms
4,380 KB
testcase_05 AC 367 ms
4,384 KB
testcase_06 AC 357 ms
4,380 KB
testcase_07 AC 326 ms
4,380 KB
testcase_08 AC 489 ms
4,376 KB
testcase_09 AC 411 ms
4,376 KB
testcase_10 AC 506 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<vector<int> > a(m+1, vector<int>(m+1));
  REP (i, m) REP (j, m) cin >> a[i+1][j+1];

  vector<vector<long long> > csum(m+1, vector<long long>(m+1));
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= m; j++)
      csum[i][j] = csum[i][j-1] + a[j][i];
  
  REP (t, n) {
    int x, y;
    cin >> y >> x;

    int ret = 0;
    for (int y2 = 1; y2 <= m; y2++) {
      for (int y1 = 1; y1 <= y2; y1++) {
        if (y < y1 || y2 < y) continue;
        unordered_map<long long, int> hist;
        hist[0]++;
        long long cur = 0;
        for (int xt = 1; xt <= m; xt++) {
          cur += csum[xt][y2] - csum[xt][y1-1];
          if (xt < x) hist[cur]++;
          else ret += hist[cur];
        }
      }
    }
    cout << ret << endl;
  }
  
  return 0;
}
0