結果

問題 No.755 Zero-Sum Rectangle
ユーザー parukiparuki
提出日時 2018-12-15 08:32:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 1,848 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 175,668 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 21:42:44
合計ジャッジ時間 4,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 198 ms
4,348 KB
testcase_02 AC 105 ms
4,348 KB
testcase_03 AC 100 ms
4,348 KB
testcase_04 AC 94 ms
4,348 KB
testcase_05 AC 91 ms
4,348 KB
testcase_06 AC 89 ms
4,348 KB
testcase_07 AC 87 ms
4,348 KB
testcase_08 AC 85 ms
4,348 KB
testcase_09 AC 86 ms
4,348 KB
testcase_10 AC 88 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
evil_1 AC 109 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

typedef ll SumType;
class Sum2D {
public:
    Sum2D() {}
    Sum2D(const vector<vector<SumType>> &a)
        :h((int)a.size()), w((int)a[0].size()), s(h + 1, vector<SumType>(w + 1))
    {
        for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j)
            s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i - 1][j - 1] - s[i - 1][j - 1];
    }

    SumType get(int sy, int sx, int ty, int tx) {
        return s[ty][tx] - s[sy][tx] - s[ty][sx] + s[sy][sx];
    }
private:
    int h, w;
    vector<vector<SumType>> s;
};

void solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> A(M, vector<ll>(M)), T(M + 1, vector<ll>(M + 1));
    rep(i, M)rep(j, M)cin >> A[i][j];
    Sum2D S(A);

    rep(sy, M)rep(sx, M)FOR(ty, sy + 1, M + 1)FOR(tx, sx + 1, M + 1) {
        ll sm = S.get(sy, sx, ty, tx);
        if (sm == 0) {
            T[sy][sx]++;
            T[sy][tx]--;
            T[ty][sx]--;
            T[ty][tx]++;
        }
    }

    rep(i, M)rep(j, M)T[i][j + 1] += T[i][j];
    rep(i, M)rep(j, M)T[i + 1][j] += T[i][j];

    rep(i, N) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        cout << T[x][y] << endl;
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0