結果
| 問題 |
No.755 Zero-Sum Rectangle
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2022-06-28 13:19:13 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 386 ms / 2,000 ms |
| コード長 | 1,640 bytes |
| コンパイル時間 | 1,010 ms |
| コンパイル使用メモリ | 142,524 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-11-21 05:23:16 |
| 合計ジャッジ時間 | 7,495 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 TLE * 1 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N, M;
cin >> N >> M;
ll A[M][M];
for (int i = 0; i < M; ++i) {
for (int j = 0; j < M; ++j) {
cin >> A[i][j];
}
}
ll S[M + 1][M + 1];
memset(S, 0, sizeof(S));
for (int y = 1; y <= M; ++y) {
for (int x = 1; x <= M; ++x) {
S[y][x] = S[y][x - 1] + A[y - 1][x - 1];
}
}
for (int x = 0; x <= M; ++x) {
for (int y = 1; y <= M; ++y) {
S[y][x] += S[y - 1][x];
}
}
/*
for (int y = 0; y <= M; ++y) {
for (int x = 0; x <= M; ++x) {
cerr << S[y][x] << " ";
}
cerr << endl;
}
*/
int x, y;
for (int i = 0; i < N; ++i) {
cin >> y >> x;
int ans = 0;
for (int cy = 1; cy <= y; ++cy) {
for (int cx = 1; cx <= x; ++cx) {
for (int ny = y; ny <= M; ++ny) {
for (int nx = x; nx <= M; ++nx) {
if (ny < cy) continue;
if (nx < cx) continue;
int ly = min(cy, ny);
int lx = min(cx, nx);
int ry = max(cy, ny);
int rx = max(cx, nx);
if (ly <= y && y <= ry && lx <= x && x <= rx) {
ll sum = S[ry][rx] - S[ry][lx - 1] - S[ly - 1][rx] + S[ly - 1][lx - 1];
// fprintf(stderr, "(%d, %d) -> (%d, %d) sum: %lld\n", lx, ly, rx, ry, sum);
if (sum == 0) ++ans;
}
}
}
}
}
cout << ans << endl;
}
return 0;
}
siman