結果

問題 No.755 Zero-Sum Rectangle
ユーザー graythunder1graythunder1
提出日時 2020-02-29 00:03:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 164,608 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-21 21:07:32
合計ジャッジ時間 7,267 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 84 ms
6,944 KB
testcase_02 AC 124 ms
6,940 KB
testcase_03 AC 163 ms
6,944 KB
testcase_04 AC 176 ms
6,944 KB
testcase_05 AC 183 ms
6,940 KB
testcase_06 AC 119 ms
6,940 KB
testcase_07 AC 110 ms
6,940 KB
testcase_08 AC 150 ms
6,944 KB
testcase_09 AC 175 ms
6,944 KB
testcase_10 AC 201 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N, M;
  cin >> N >> M;
  ll A[M][M];
  rep(i, M) rep(j, M) cin >> A[i][j];
  ll x[N], y[N], ans[N] = {};
  rep(i, N) cin >> x[i] >> y[i];

  ll sum[M+1][M+1];
  rep(i, M+1){
    sum[0][i] = 0;
    sum[i][0] = 0;
  }
  rep(i, M) rep(j, M)
    sum[i+1][j+1] = A[i][j] + sum[i+1][j] + sum[i][j+1] - sum[i][j];

  rep(n, N){
    // printf("i:%lld j:%lld\n", x[n], y[n]);
    rep(i1, x[n]) rep(j1, y[n]) repi(i2, x[n], M+1) repi(j2, y[n], M+1){
      ll s = sum[i2][j2] - sum[i2][j1] - sum[i1][j2] + sum[i1][j1];
      if(s == 0) ans[n]++;
      // printf("i:%lld j:%lld sum:%lld\n", x[n], y[n], s);
    }
    cout << ans[n] << endl;
  }
  return 0;
}
0