結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 170 ms
4,348 KB
testcase_02 AC 67 ms
4,348 KB
testcase_03 AC 62 ms
4,348 KB
testcase_04 AC 58 ms
4,348 KB
testcase_05 AC 49 ms
4,348 KB
testcase_06 AC 45 ms
4,348 KB
testcase_07 AC 42 ms
4,348 KB
testcase_08 AC 42 ms
4,348 KB
testcase_09 AC 43 ms
4,348 KB
testcase_10 AC 41 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
evil_1 AC 67 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<int,130>,130> A{};
    array<array<int,131>,131> B{};
    int n, m;
    cin >> n >> m;
    for(int y = 0; y < m; y++){
        for(int x = 0; x < m; x++){
            cin >> A[y][x];
        }
    }
    vector<pair<ll,int>> temp(m + 1);
    array<ll, 130> C{};
    for(int ly = 0; ly < m; ly++){
        C.fill(0);
        for(int ry = ly + 1; ry <= m; ry++){
            temp[0] = make_pair(0, 0);
            for(int x = 0, y = ry - 1; x < m; x++){
                C[x] += A[y][x];
                temp[x + 1] = make_pair(temp[x].first + C[x], x + 1);
            }
            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