結果
| 問題 |
No.755 Zero-Sum Rectangle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-15 08:32:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 208 ms / 2,000 ms |
| コード長 | 1,848 bytes |
| コンパイル時間 | 1,777 ms |
| コンパイル使用メモリ | 176,800 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-25 06:13:02 |
| 合計ジャッジ時間 | 3,660 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
ソースコード
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
typedef ll SumType;
class Sum2D {
public:
Sum2D() {}
Sum2D(const vector<vector<SumType>> &a)
:h((int)a.size()), w((int)a[0].size()), s(h + 1, vector<SumType>(w + 1))
{
for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j)
s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i - 1][j - 1] - s[i - 1][j - 1];
}
SumType get(int sy, int sx, int ty, int tx) {
return s[ty][tx] - s[sy][tx] - s[ty][sx] + s[sy][sx];
}
private:
int h, w;
vector<vector<SumType>> s;
};
void solve() {
int N, M;
cin >> N >> M;
vector<vector<ll>> A(M, vector<ll>(M)), T(M + 1, vector<ll>(M + 1));
rep(i, M)rep(j, M)cin >> A[i][j];
Sum2D S(A);
rep(sy, M)rep(sx, M)FOR(ty, sy + 1, M + 1)FOR(tx, sx + 1, M + 1) {
ll sm = S.get(sy, sx, ty, tx);
if (sm == 0) {
T[sy][sx]++;
T[sy][tx]--;
T[ty][sx]--;
T[ty][tx]++;
}
}
rep(i, M)rep(j, M)T[i][j + 1] += T[i][j];
rep(i, M)rep(j, M)T[i + 1][j] += T[i][j];
rep(i, N) {
int x, y;
cin >> x >> y;
--x; --y;
cout << T[x][y] << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}