結果

問題 No.755 Zero-Sum Rectangle
ユーザー polyomino_24
提出日時 2018-12-06 02:50:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 101,740 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-09-13 12:51:13
合計ジャッジ時間 5,880 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll sum[135][135];
int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m){
        rep(j,m){
            cin >> sum[i][j];
        }
    }
    rep(i,m)rep(j,m)sum[i][j+1] +=sum[i][j];
    rep(i,m)rep(j,m)sum[i+1][j] +=sum[i][j];
    
    while(n--){
        int x,y;
        cin >> x >> y;
        x--,y--;
        int ans =0;
        rep(a,x+1)for(int b = x; b < m; b++)rep(c,y+1)for(int d = y; d < m; d++){
            ll s = sum[b][d];
            if(a>0)s -= sum[a-1][d];
            if(c>0)s -= sum[b][c-1];
            if(a>0 and c > 0) s+=sum[a-1][c-1];
            if(s==0)ans++;
        }
        cout << ans << endl;
    }
}
0