結果

問題 No.755 Zero-Sum Rectangle
ユーザー hirokazu1020hirokazu1020
提出日時 2018-12-03 00:30:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 1,597 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 104,872 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 21:00:38
合計ジャッジ時間 8,129 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 63 ms
4,380 KB
testcase_02 AC 202 ms
4,376 KB
testcase_03 AC 309 ms
4,380 KB
testcase_04 AC 396 ms
4,380 KB
testcase_05 AC 422 ms
4,380 KB
testcase_06 AC 377 ms
4,376 KB
testcase_07 AC 325 ms
4,380 KB
testcase_08 AC 510 ms
4,380 KB
testcase_09 AC 411 ms
4,376 KB
testcase_10 AC 488 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0