結果

問題 No.755 Zero-Sum Rectangle
ユーザー tsutajtsutaj
提出日時 2019-04-28 00:43:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 2,135 bytes
コンパイル時間 1,402 ms
コンパイル使用メモリ 112,312 KB
実行使用メモリ 8,080 KB
最終ジャッジ日時 2023-08-20 05:23:08
合計ジャッジ時間 7,904 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,080 KB
testcase_01 AC 66 ms
4,376 KB
testcase_02 AC 174 ms
4,380 KB
testcase_03 AC 252 ms
4,376 KB
testcase_04 AC 328 ms
4,380 KB
testcase_05 AC 357 ms
4,380 KB
testcase_06 AC 344 ms
4,380 KB
testcase_07 AC 319 ms
4,380 KB
testcase_08 AC 478 ms
4,380 KB
testcase_09 AC 403 ms
4,376 KB
testcase_10 AC 498 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#include <unordered_map>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int A[135][135], sum[135][135];

int get_sum(int lx, int ly, int rx, int ry) {
    return sum[rx][ry] - sum[lx][ry] - sum[rx][ly] + sum[lx][ly];
}

signed main() {
    int N, M; cin >> N >> M;
    for(int i=0; i<M; i++) {
        for(int j=0; j<M; j++) {
            cin >> A[i+1][j+1];
            sum[i+1][j+1] = A[i+1][j+1];
        }
    }

    for(int i=1; i<=M; i++) {
        for(int j=1; j<=M; j++) {
            sum[i][j] += sum[i][j-1];
        }
    }

    for(int j=1; j<=M; j++) {
        for(int i=1; i<=M; i++) {
            sum[i][j] += sum[i-1][j];
        }
    }

    while(N--) {
        int x, y; cin >> x >> y;

        int ans = 0;
        for(int tx=0; tx<x; tx++) {
            for(int bx=x; bx<=M; bx++) {
                unordered_map<int, int> cnt;
                for(int ly=0; ly<y; ly++) {
                    int sl = sum[tx][ly] - sum[bx][ly];
                    cnt[sl]++;
                }

                for(int ry=y; ry<=M; ry++) {
                    int sr = sum[tx][ry] - sum[bx][ry];
                    ans += cnt[sr];
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0