結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 208 ms
4,380 KB
testcase_02 AC 114 ms
4,376 KB
testcase_03 AC 105 ms
4,376 KB
testcase_04 AC 98 ms
4,376 KB
testcase_05 AC 94 ms
4,376 KB
testcase_06 AC 92 ms
4,376 KB
testcase_07 AC 92 ms
4,380 KB
testcase_08 AC 91 ms
4,376 KB
testcase_09 AC 92 ms
4,376 KB
testcase_10 AC 92 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
evil_1 AC 115 ms
4,376 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 + 1, vector<ll>(M + 1));
    rep(i,M)rep(j,M) cin >> A[i + 1][j + 1];
    rep(i,M+1)rep(j,M) A[i][j + 1] += A[i][j];
    rep(i,M)rep(j,M+1) A[i + 1][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[i][j] - A[x][j] - A[i][y] + A[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