結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー |
|
提出日時 | 2018-12-04 08:59:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 115 ms / 2,000 ms |
コード長 | 779 bytes |
コンパイル時間 | 1,405 ms |
コンパイル使用メモリ | 167,312 KB |
実行使用メモリ | 13,884 KB |
最終ジャッジ日時 | 2024-07-06 11:53:39 |
合計ジャッジ時間 | 6,322 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 TLE * 1 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,n) for (int i=0;i<(n);i++)#define REP2(i,m,n) for (int i=m;i<(n);i++)typedef long long ll;typedef long double ld;int N, M;ll A[150][150];ll sm(int r1, int c1, int r2, int c2) {return A[r2+1][c2+1] - A[r1][c2+1] - A[r2+1][c1] + A[r1][c1];}void solve() {cin >> N >> M;REP(i, M) REP(j, M) cin >> A[i+1][j+1];REP(i, M+1) REP(j, M) A[i][j+1] += A[i][j];REP(j, M+1) REP(i, M) A[i+1][j] += A[i][j];while (N--) {int r, c; cin >> r >> c; --r, --c;ll ans = 0;REP(r1, r+1) REP(c1, c+1) REP2(r2, r, M) REP2(c2, c, M) ans += !sm(r1, c1, r2, c2);cout << ans << "\n";}}int main() {cin.tie(0);ios::sync_with_stdio(false);solve();}