結果

問題 No.755 Zero-Sum Rectangle
ユーザー treeonetreeone
提出日時 2018-12-03 00:06:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,719 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 202,948 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 21:00:03
合計ジャッジ時間 6,737 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 91 ms
4,376 KB
testcase_02 AC 74 ms
4,376 KB
testcase_03 AC 97 ms
4,376 KB
testcase_04 AC 113 ms
4,380 KB
testcase_05 AC 124 ms
4,376 KB
testcase_06 AC 81 ms
4,380 KB
testcase_07 AC 74 ms
4,376 KB
testcase_08 AC 103 ms
4,380 KB
testcase_09 AC 114 ms
4,376 KB
testcase_10 AC 129 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct CumulativeSum2D{
    vector<vector<int> > data;
    CumulativeSum2D(int H, int W) : data(H + 1, vector<int>(W + 1, 0)) {}
    void add(int x, int y, int z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }
    void build(){
        for(int i = 1; i < data.size(); i++) {
        for(int j = 1; j < data[i].size(); j++) {
            data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }
    int query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    CumulativeSum2D cs(m, m);
    rep(i, 0, m){
        rep(j, 0, m){
            int a;
            cin >> a;
            cs.add(i, j, a);
        }
    }
    cs.build();
    while(n--){
        int x, y;
        cin >> x >> y;
        x--; y--;
        int ans = 0;
        for(int i = 0; i <= x; i++){
            for(int j = 0; j <= y; j++){
                for(int k = x; k < m; k++){
                    for(int l = y; l < m; l++){
                        int tmp = cs.query(i, j, k + 1, l + 1);
                        if(tmp == 0) ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}
0