結果
| 問題 |
No.755 Zero-Sum Rectangle
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2019-08-27 11:33:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 478 ms / 2,000 ms |
| コード長 | 3,233 bytes |
| コンパイル時間 | 2,006 ms |
| コンパイル使用メモリ | 177,380 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-14 06:16:04 |
| 合計ジャッジ時間 | 4,982 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
ソースコード
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;
int main() {
int n, m; cin >> n >> m;
vector<vector<int>> a(m, vector<int>(m));
vector<vector<ll>> s(m, vector<ll>(m));
vector<vector<int>> ans(m, vector<int>(m, 0));
REP(i, m) {
REP(j, m) {
cin >> a[i][j];
}
}
REP(i, m) {
REP(j, m) {
s[i][j] = a[i][j];
if (i > 0) s[i][j] += s[i - 1][j];
if (j > 0) s[i][j] += s[i][j - 1];
if (i > 0 && j > 0) s[i][j] -= s[i - 1][j - 1];
}
}
REP(i1, m) {
REP(j1, m) {
FOR(i2, i1, m) {
FOR(j2, j1, m) {
if (i1 > 0) {
if (j1 > 0) {
if (s[i2][j2] + s[i1 - 1][j1 - 1] - s[i2][j1 - 1] - s[i1 - 1][j2] == 0) {
ans[i1][j1] += 1;
if (i2 < m - 1) ans[i2 + 1][j1] -= 1;
if (j2 < m - 1) ans[i1][j2 + 1] -= 1;
if (i2 < m - 1 && j2 < m - 1) ans[i2 + 1][j2 + 1] += 1;
}
}
else {
if (s[i2][j2] - s[i1 - 1][j2] == 0) {
ans[i1][j1] += 1;
if (i2 < m - 1) ans[i2 + 1][j1] -= 1;
if (j2 < m - 1) ans[i1][j2 + 1] -= 1;
if (i2 < m - 1 && j2 < m - 1) ans[i2 + 1][j2 + 1] += 1;
}
}
}
else {
if (j1 > 0) {
if (s[i2][j2] - s[i2][j1 - 1] == 0) {
ans[i1][j1] += 1;
if (i2 < m - 1) ans[i2 + 1][j1] -= 1;
if (j2 < m - 1) ans[i1][j2 + 1] -= 1;
if (i2 < m - 1 && j2 < m - 1) ans[i2 + 1][j2 + 1] += 1;
}
}
else {
if (s[i2][j2] == 0) {
ans[i1][j1] += 1;
if (i2 < m - 1) ans[i2 + 1][j1] -= 1;
if (j2 < m - 1) ans[i1][j2 + 1] -= 1;
if (i2 < m - 1 && j2 < m - 1) ans[i2 + 1][j2 + 1] += 1;
}
}
}
}
}
}
}
REP(i, m) {
REP(j, m - 1) {
ans[i][j + 1] += ans[i][j];
}
}
REP(i, m) {
REP(j, m - 1) {
ans[j + 1][i] += ans[j][i];
}
}
REP(i, n) {
int x, y; cin >> x >> y;
x--; y--;
cout << ans[x][y] << endl;
}
getchar(); getchar();
}
🍮かんプリン