結果

問題 No.755 Zero-Sum Rectangle
ユーザー HaarHaar
提出日時 2018-12-06 09:20:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 171,472 KB
実行使用メモリ 7,884 KB
最終ジャッジ日時 2023-10-12 00:08:28
合計ジャッジ時間 6,551 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,884 KB
testcase_01 AC 92 ms
4,348 KB
testcase_02 AC 74 ms
4,352 KB
testcase_03 AC 98 ms
4,352 KB
testcase_04 AC 113 ms
4,348 KB
testcase_05 AC 124 ms
4,348 KB
testcase_06 AC 81 ms
4,352 KB
testcase_07 AC 73 ms
4,352 KB
testcase_08 AC 102 ms
4,348 KB
testcase_09 AC 115 ms
4,352 KB
testcase_10 AC 128 ms
4,348 KB
testcase_11 AC 2 ms
4,352 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;}

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];

  vector<vector<LLI>> memo(m+1, vector<LLI>(m+1));

  REP(i,m) REP(j,m) memo[i+1][j+1] = a[i][j];

  FORE(i,1,m)
    REPE(j,m)
      memo[i][j] += memo[i-1][j];

  REPE(i,m)
    FORE(j,1,m)
      memo[i][j] += memo[i][j-1];

  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(memo[x2][y2] - memo[x1-1][y2] - memo[x2][y1-1] + memo[x1-1][y1-1] == 0) ++ans;
    }
    cout << ans << endl;
  }
  
  return 0;
}
0