結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー |
![]() |
提出日時 | 2022-06-28 13:16:45 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,639 bytes |
コンパイル時間 | 1,672 ms |
コンパイル使用メモリ | 142,888 KB |
実行使用メモリ | 13,636 KB |
最終ジャッジ日時 | 2024-11-21 05:20:09 |
合計ジャッジ時間 | 8,280 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 WA * 1 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) { int sum = S[ry][rx] - S[ry][lx - 1] - S[ly - 1][rx] + S[ly - 1][lx - 1]; // fprintf(stderr, "(%d, %d) -> (%d, %d) sum: %d\n", lx, ly, rx, ry, sum); if (sum == 0) ++ans; } } } } } cout << ans << endl; } return 0; }