結果

問題 No.755 Zero-Sum Rectangle
ユーザー tkmst201tkmst201
提出日時 2021-01-26 11:38:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,388 bytes
コンパイル時間 2,980 ms
コンパイル使用メモリ 206,344 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 15:44:10
合計ジャッジ時間 4,845 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 199 ms
4,376 KB
testcase_02 AC 119 ms
4,380 KB
testcase_03 AC 110 ms
4,380 KB
testcase_04 AC 105 ms
4,380 KB
testcase_05 AC 100 ms
4,380 KB
testcase_06 AC 98 ms
4,380 KB
testcase_07 AC 98 ms
4,380 KB
testcase_08 AC 97 ms
4,376 KB
testcase_09 AC 98 ms
4,376 KB
testcase_10 AC 98 ms
4,380 KB
testcase_11 WA -
evil_1 AC 120 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	vector A(M, vector(M, 0));
	REP(i, M) REP(j, M) scanf("%d", &A[i][j]);
	vector sum(M + 1, vector(M + 1, 0ll));
	REP(i, M) REP(j, M) sum[i + 1][j + 1] = A[i][j];
	REP(i, M + 1) REP(j, M) sum[i][j + 1] += sum[i][j];
	REP(i, M) REP(j, M + 1) sum[i + 1][j] += sum[i][j];
	
	vector ans(M + 1, vector(M + 1, 0));
	REP(y1, M) FOR(y2, y1 + 1, M + 1) REP(x1, M) FOR(x2, x1 + 1, M + 1) {
		int s = sum[y2][x2] - sum[y1][x2] - sum[y2][x1] + sum[y1][x1];
		if (s == 0) {
			++ans[y1][x1];
			--ans[y1][x2];
			--ans[y2][x1];
			++ans[y2][x2];
		}
	}
	
	REP(i, M + 1) REP(j, M) ans[i][j + 1] += ans[i][j];
	REP(i, M) REP(j, M + 1) ans[i + 1][j] += ans[i][j];
	
	REP(i, N) {
		int x, y;
		scanf("%d %d", &x, &y);
		printf("%d\n", ans[x - 1][y - 1]);
	}
}
0