結果

問題 No.755 Zero-Sum Rectangle
ユーザー tottoripapertottoripaper
提出日時 2018-12-25 01:12:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 524 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 2,836 ms
コンパイル使用メモリ 176,792 KB
実行使用メモリ 7,912 KB
最終ジャッジ日時 2023-10-26 03:09:25
合計ジャッジ時間 9,414 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,912 KB
testcase_01 AC 16 ms
4,348 KB
testcase_02 AC 207 ms
4,348 KB
testcase_03 AC 352 ms
4,348 KB
testcase_04 AC 403 ms
4,348 KB
testcase_05 AC 466 ms
4,348 KB
testcase_06 AC 415 ms
4,348 KB
testcase_07 AC 441 ms
4,348 KB
testcase_08 AC 403 ms
4,348 KB
testcase_09 AC 524 ms
4,348 KB
testcase_10 AC 503 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M;
ll A[140][140];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M;

    for(int i=1;i<=M;++i){
        for(int j=1;j<=M;++j){
            std::cin >> A[i][j];
        }

        for(int j=2;j<=M;++j){
            A[i][j] += A[i][j-1];
        }
    }
    
    for(int i=0;i<N;++i){
        int x, y;
        std::cin >> x >> y;

        std::swap(x, y);

        ll res = 0;
        
        for(int i=1;i<=x;++i){
            for(int j=x;j<=M;++j){
                ll sum = 0;
                std::map<ll, int> cnt;
                cnt[0] = 1;
                
                for(int k=1;k<y;++k){
                    sum += A[k][j] - A[k][i-1];
                    cnt[sum] += 1;
                }

                for(int k=y;k<=M;++k){
                    sum += A[k][j] - A[k][i-1];
                    res += cnt[sum];
                }
            }
        }

        std::cout << res << std::endl;
    }
}
0