結果
| 問題 |
No.755 Zero-Sum Rectangle
|
| コンテスト | |
| ユーザー |
tkmst201
|
| 提出日時 | 2021-01-26 11:38:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 203 ms / 2,000 ms |
| コード長 | 1,387 bytes |
| コンパイル時間 | 2,081 ms |
| コンパイル使用メモリ | 201,040 KB |
| 最終ジャッジ日時 | 2025-01-18 08:21:32 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | REP(i, M) REP(j, M) scanf("%d", &A[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//
int main() {
int N, M;
cin >> N >> M;
vector A(M, vector(M, 0));
REP(i, M) REP(j, M) scanf("%d", &A[i][j]);
vector sum(M + 1, vector(M + 1, 0ll));
REP(i, M) REP(j, M) sum[i + 1][j + 1] = A[i][j];
REP(i, M + 1) REP(j, M) sum[i][j + 1] += sum[i][j];
REP(i, M) REP(j, M + 1) sum[i + 1][j] += sum[i][j];
vector ans(M + 1, vector(M + 1, 0));
REP(y1, M) FOR(y2, y1 + 1, M + 1) REP(x1, M) FOR(x2, x1 + 1, M + 1) {
ll s = sum[y2][x2] - sum[y1][x2] - sum[y2][x1] + sum[y1][x1];
if (s == 0) {
++ans[y1][x1];
--ans[y1][x2];
--ans[y2][x1];
++ans[y2][x2];
}
}
REP(i, M + 1) REP(j, M) ans[i][j + 1] += ans[i][j];
REP(i, M) REP(j, M + 1) ans[i + 1][j] += ans[i][j];
REP(i, N) {
int x, y;
scanf("%d %d", &x, &y);
printf("%d\n", ans[x - 1][y - 1]);
}
}
tkmst201