結果

問題 No.755 Zero-Sum Rectangle
ユーザー FF256grhyFF256grhy
提出日時 2018-12-03 00:33:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 2,654 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 171,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 21:00:54
合計ジャッジ時間 8,775 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 305 ms
4,376 KB
testcase_02 AC 235 ms
4,380 KB
testcase_03 AC 331 ms
4,376 KB
testcase_04 AC 381 ms
4,376 KB
testcase_05 AC 402 ms
4,380 KB
testcase_06 AC 262 ms
4,376 KB
testcase_07 AC 245 ms
4,376 KB
testcase_08 AC 334 ms
4,376 KB
testcase_09 AC 380 ms
4,376 KB
testcase_10 AC 432 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define V2(T, x, y) (x, vector<T>(y, 0LL))
template<typename T> struct Sum2 {
	typedef vector<vector<T>> A;
	A s;
	int X, Y;
	Sum2() { X = Y = -1; }
	Sum2(A & p) { init(p); }
	void init(A & p) {
		X = p.size();
		Y = p[0].size();
		s = A V2(T, X + 1, Y + 1);
		inc1(x, X) { inc1(y, Y) { s[x][y]  = p[x - 1][y - 1]; } }
		inc1(x, X) { inc1(y, Y) { s[x][y] += s[x - 1][y    ]; } }
		inc1(x, X) { inc1(y, Y) { s[x][y] += s[x    ][y - 1]; } }
	}
	T sum(int xl, int xh, int yl, int yh) { // [xl, xh) × [yl, yh)
		assert(inII(xl, 0, X));
		assert(inII(xh, 0, X));
		assert(inII(yl, 0, Y));
		assert(inII(yh, 0, Y));
		assert(xl <= xh);
		assert(yl <= yh);
		return s[xh][yh] - s[xh][yl] - s[xl][yh] + s[xl][yl];
	}
};

// ----

vector<vector<LL>> a V2(LL, 130, 130);

LL m, n, x[10], y[10];

int main() {
	cin >> n >> m;
	inc(i, m) {
	inc(j, m) {
		cin >> a[i][j];
	}
	}
	Sum2<LL> s(a);
	
	inc(q, n) {
		int x, y;
		cin >> x >> y;
		
		int ans = 0;
		incID(il, 0, x) {
		incID(jl, 0, y) {
		incII(ih, x, m) {
		incII(jh, y, m) {
			if(s.sum(il, ih, jl, jh) == 0) { ans++; }
		}
		}
		}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}
0