結果
| 問題 | No.755 Zero-Sum Rectangle | 
| コンテスト | |
| ユーザー |  hirokazu1020 | 
| 提出日時 | 2018-12-03 00:30:03 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 529 ms / 2,000 ms | 
| コード長 | 1,597 bytes | 
| コンパイル時間 | 1,019 ms | 
| コンパイル使用メモリ | 106,612 KB | 
| 実行使用メモリ | 13,752 KB | 
| 最終ジャッジ日時 | 2024-07-01 05:29:43 | 
| 合計ジャッジ時間 | 8,107 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 11 TLE * 1 | 
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
int n, m;
int a[130][130];
long long asum[131][130];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	rep(i,m)rep(j,m) {
		cin >> a[i][j];
		asum[i+1][j] = a[i][j];
	}
	rep(i,m) rep(j,m){
		asum[i + 1][j] += asum[i][j];
	}
	rep(i,n) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		swap(x, y);
		long long ans = 0;
		for (int y1 = 0; y1 <= y;y1++) {
			for (int y2 = y; y2 < m;y2++) {
				long long centor = asum[y2 + 1][x] - asum[y1][x];
				unordered_map<long long, int > lc, rc;
				long long s;
				s = centor;
				lc[centor] = 1;
				for (int x1 = x - 1; x1 >= 0; x1--) {
					s += asum[y2 + 1][x1] - asum[y1][x1];
					lc[s]++;
				}
				s = 0;
				rc[0] = 1;
				for (int x2 = x + 1; x2 < m; x2++) {
					s += asum[y2 + 1][x2] - asum[y1][x2];
					rc[s]++;
				}
				for (auto p : lc) {
					long long v = p.first;
					auto it = rc.find(-v);
					if (it != rc.end()) {
						ans += p.second * it->second;
					}
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}
            
            
            
        