結果

問題 No.755 Zero-Sum Rectangle
ユーザー outlineoutline
提出日時 2020-12-21 23:04:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,085 ms / 2,000 ms
コード長 2,625 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 138,112 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 11:56:29
合計ジャッジ時間 7,605 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1,085 ms
4,348 KB
testcase_02 AC 137 ms
4,348 KB
testcase_03 AC 110 ms
4,348 KB
testcase_04 AC 90 ms
4,348 KB
testcase_05 AC 78 ms
4,348 KB
testcase_06 AC 72 ms
4,348 KB
testcase_07 AC 68 ms
4,348 KB
testcase_08 AC 68 ms
4,348 KB
testcase_09 AC 69 ms
4,348 KB
testcase_10 AC 68 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<typename T>
struct CumulativeSum2D{
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<T>(H + 1, 0)) {}

    void add(int x, int y, T z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }

    void build(){
        for(int i = 1; i < (int)data.size(); ++i){
            for(int j = 1; j < (int)data[i].size(); ++j){
                data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

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

    int N, M;
    cin >> N >> M;
    CumulativeSum2D<ll> S(M, M);
    for(int i = 0; i < M; ++i){
        for(int j = 0; j < M; ++j){
            ll A;
            cin >> A;
            S.add(i, j, A);
        }
    }
    vector<int> X(N), Y(N);
    for(int i = 0; i < N; ++i){
        cin >> X[i] >> Y[i];
        --X[i], --Y[i];
    }
    S.build();

    vector<int> ans(N);
    for(int sx = 0; sx < M; ++sx){
        for(int sy = 0; sy < M; ++sy){
            for(int gx = sx + 1; gx <= M; ++gx){
                for(int gy = sy + 1; gy <= M; ++gy){
                    if(S.query(sx, sy, gx, gy) == 0LL){
                        for(int i = 0; i < N; ++i){
                            if(sx <= X[i] && X[i] < gx && sy <= Y[i] && Y[i] < gy){
                                ans[i] += 1;
                            }
                        }
                    }
                }
            }
        }
    }
    
    for(int i = 0; i < N; ++i)  cout << ans[i] << '\n';

    return 0;
}
0