結果

問題 No.755 Zero-Sum Rectangle
ユーザー rogi52rogi52
提出日時 2022-10-12 23:45:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 204,900 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 18:42:47
合計ジャッジ時間 4,765 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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