結果

問題 No.755 Zero-Sum Rectangle
ユーザー rogi52
提出日時 2022-10-12 23:45:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 200,588 KB
最終ジャッジ日時 2025-02-08 02:19:13
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<vector<ll>> A(M, vector<ll>(M));
    rep(i,M)rep(j,M) cin >> A[i][j];
    vector<vector<ll>> A_sum(M + 1, vector<ll>(M + 1, 0));
    rep(i,M)rep(j,M) A_sum[i + 1][j + 1] = A_sum[i][j + 1] + A_sum[i + 1][j] - A_sum[i][j] + A[i][j];

    vector<vector<ll>> imos(M + 1, vector<ll>(M + 1, 0));
    rep(x,M)rep(y,M) {
        for(int i = x + 1; i <= M; i++) for(int j = y + 1; j <= M; j++) {
            ll SUM = A_sum[i][j] - A_sum[x][j] - A_sum[i][y] + A_sum[x][y];
            if(SUM == 0LL) {
                imos[x][y]++;
                imos[x][j]--;
                imos[i][y]--;
                imos[i][j]++;
            }
        }
    }

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

    rep(i,N) {
        int x,y; cin >> x >> y; x--; y--;
        cout << imos[x][y] << "\n";
    }
}
0