結果

問題 No.755 Zero-Sum Rectangle
ユーザー t98slidert98slider
提出日時 2023-03-31 19:53:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,652 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 176,356 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 05:51:51
合計ジャッジ時間 3,388 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 164 ms
4,348 KB
testcase_02 AC 68 ms
4,348 KB
testcase_03 AC 63 ms
4,348 KB
testcase_04 AC 59 ms
4,348 KB
testcase_05 AC 50 ms
4,348 KB
testcase_06 AC 46 ms
4,348 KB
testcase_07 AC 45 ms
4,348 KB
testcase_08 AC 43 ms
4,348 KB
testcase_09 AC 45 ms
4,348 KB
testcase_10 AC 43 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
evil_1 AC 68 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    array<array<ll,131>,131> A{};
    array<array<int,131>,131> B{};
    int n, m;
    cin >> n >> m;
    for(int y = 1; y <= m; y++){
        for(int x = 1; x <= m; x++){
            cin >> A[y][x];
            A[y][x] += A[y][x - 1] + A[y - 1][x] - A[y - 1][x - 1];
        }
    }
    vector<pair<ll,int>> temp(m + 1);
    ll offset;
    for(int ly = 0; ly < m; ly++){
        for(int ry = ly + 1; ry <= m; ry++){
            temp[0] = make_pair(0, 0);
            offset = -A[ry][0] + A[ly][0];
            for(int x = 1; x <= m; x++){
                temp[x] = make_pair(A[ry][x] - A[ly][x] + offset, x);
            }
            sort(temp.begin(), temp.end());
            for(int i = 0; i < m; ){
                int p = i++;
                while(i <= m && temp[i].first == temp[p].first) i++;
                for(int j = p; j + 1 < i; j++){
                    for(int k = j + 1; k < i; k++){
                        B[ry][temp[k].second]++;
                        B[ly][temp[k].second]--;
                        B[ry][temp[j].second]--;
                        B[ly][temp[j].second]++;
                    }
                }
            }
        }
    }
    for(int i = 0; i < 131; i++) {
        for(int j = 1; j < 131; j++) {
            B[i][j] += B[i][j - 1];
        }
    }
    for(int i = 0; i < 131; i++) {
        for(int j = 1; j < 131; j++) {
            B[j][i] += B[j - 1][i];
        }
    }
    while(n--){
        int y, x;
        cin >> y >> x;
        cout << B[--y][--x] << '\n';
    }
}
0