結果
| 問題 | No.755 Zero-Sum Rectangle | 
| コンテスト | |
| ユーザー |  lapi | 
| 提出日時 | 2019-07-01 19:25:51 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 138 ms / 2,000 ms | 
| コード長 | 1,358 bytes | 
| コンパイル時間 | 1,059 ms | 
| コンパイル使用メモリ | 103,288 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-18 02:48:02 | 
| 合計ジャッジ時間 | 3,226 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 11 WA * 1 | 
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
ll sum[131][131]; // sum[i][j] : 長方形[1,i]×[1,j]の中の値の総和
int x[10], y[10];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= M; j++) cin >> sum[i][j];
	}
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
	// 以下2次元累積和
	for (int k = 0; k <= M; k++) sum[0][k] = sum[k][0] = 0;
	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];
	}
	for (int i = 0; i < N; i++) {
		int cnt = 0;
		for (int px = 1; px <= x[i]; px++) {
			for (int qx = x[i]; qx <= M; qx++) {
				for (int py = 1; py <= y[i]; py++) {
					for (int qy = y[i]; qy <= M; qy++) {
						ll tot = sum[qx][qy] - sum[qx][py - 1] - sum[px - 1][qy] + sum[px - 1][py - 1];
						if (tot == 0) cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}
            
            
            
        