結果

問題 No.755 Zero-Sum Rectangle
ユーザー peroonperoon
提出日時 2019-06-21 05:15:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 772 ms / 2,000 ms
コード長 1,788 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 165,460 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-25 04:38:24
合計ジャッジ時間 12,692 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 652 ms
4,376 KB
testcase_02 AC 662 ms
4,380 KB
testcase_03 AC 714 ms
4,380 KB
testcase_04 AC 746 ms
4,384 KB
testcase_05 AC 757 ms
4,376 KB
testcase_06 AC 668 ms
4,384 KB
testcase_07 AC 640 ms
4,384 KB
testcase_08 AC 708 ms
4,380 KB
testcase_09 AC 731 ms
4,376 KB
testcase_10 AC 772 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

ll A[150][150];

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

    // input
    ll N, M;
    cin >> N >> M;
    ll H = M;
    ll W = M;

    FOR(i, 1, M+1){
        FOR(j, 1, M+1){
            cin >> A[i][j];
        }
    }

    // 二次元累積和
    // 横
    FOR(i, 0, H+1){
        FOR(j, 0, W+1){
            A[i][j+1] += A[i][j];
        }
    }
    // 縦
    FOR(w, 0, W+1){
        FOR(h, 0, H+1){
            A[h+1][w] += A[h][w];
        }
    }

    ll Q = N;
    while(Q--){
        ll x, y;
        cin >> x >> y;
        
        ll count = 0;
        FOR(x0, 1, W+1){
            FOR(x1, x0, W+1){
                FOR(y0, 1, H+1){
                    FOR(y1, y0, H+1){
                        if(x0<=x && x<=x1 && y0<=y && y<=y1){

                            // x, yが縦と横どちらを指しているか注意
                            //ll sum = A[y1][x1] - A[y0-1][x1] - A[y1][x0-1] + A[y0-1][x0-1];
                            ll sum = A[x1][y1] - A[x0-1][y1] - A[x1][y0-1] + A[x0-1][y0-1];
                            
                            if(sum==0){
                                count++;
                            }
                        }
                    }
                }
            }
        }
        p(count);
    }
    
    return 0;
}
0