結果

問題 No.755 Zero-Sum Rectangle
ユーザー graythunder1graythunder1
提出日時 2020-02-29 00:02:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 161,064 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-21 21:07:25
合計ジャッジ時間 7,234 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 76 ms
5,376 KB
testcase_02 AC 96 ms
5,376 KB
testcase_03 AC 132 ms
5,376 KB
testcase_04 AC 139 ms
5,376 KB
testcase_05 AC 141 ms
5,376 KB
testcase_06 AC 91 ms
5,376 KB
testcase_07 AC 87 ms
5,376 KB
testcase_08 AC 123 ms
5,376 KB
testcase_09 AC 136 ms
5,376 KB
testcase_10 AC 156 ms
5,376 KB
testcase_11 AC 2 ms
5,376 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