結果

問題 No.755 Zero-Sum Rectangle
ユーザー HaarHaar
提出日時 2018-12-06 10:03:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 171,208 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-13 17:42:45
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 91 ms
4,380 KB
testcase_02 AC 73 ms
4,376 KB
testcase_03 AC 98 ms
4,376 KB
testcase_04 AC 112 ms
4,380 KB
testcase_05 AC 122 ms
4,380 KB
testcase_06 AC 79 ms
4,376 KB
testcase_07 AC 74 ms
4,376 KB
testcase_08 AC 101 ms
4,376 KB
testcase_09 AC 114 ms
4,376 KB
testcase_10 AC 127 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}

template <typename T> class Accum2D{
public:
  vector<vector<T>> accum;

  Accum2D(vector<vector<T>> &vv){
    int d1 = vv.size(), d2 = vv[0].size();
    accum = vector<vector<T>>(d1+1, vector<T>(d2+1));
    REP(i,d1) REP(j,d2) accum[i+1][j+1] = vv[i][j];
    FORE(i,1,d1) REPE(j,d2) accum[i][j] += accum[i-1][j];
    REPE(i,d1) FORE(j,1,d2) accum[i][j] += accum[i][j-1];
  }

  // 1-indexed
  T sum(int x1, int y1, int x2, int y2){
    return accum[x2][y2] - accum[x1-1][y2] - accum[x2][y1-1] + accum[x1-1][y1-1];
  }
};

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

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

  vector<vector<LLI>> a(m, vector<LLI>(m));

  REP(i,m) REP(j,m) cin >> a[i][j];

  Accum2D<LLI> acc(a);

  REP(_,n){
    int x,y; cin >> x >> y;
    int ans = 0;
    
    FORE(x1,1,x) FORE(y1,1,y) FORE(x2,x,m) FORE(y2,y,m){
      if(acc.sum(x1,y1,x2,y2) == 0) ++ans;
    }
    cout << ans << endl;
  }
  
  return 0;
}
0