結果

問題 No.755 Zero-Sum Rectangle
ユーザー PachicobuePachicobue
提出日時 2018-12-03 17:19:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,171 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 201,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 21:12:57
合計ジャッジ時間 4,061 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 151 ms
4,376 KB
testcase_02 AC 114 ms
4,380 KB
testcase_03 AC 105 ms
4,376 KB
testcase_04 AC 101 ms
4,376 KB
testcase_05 AC 97 ms
4,376 KB
testcase_06 AC 94 ms
4,380 KB
testcase_07 AC 94 ms
4,380 KB
testcase_08 AC 95 ms
4,376 KB
testcase_09 AC 96 ms
4,380 KB
testcase_10 AC 98 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
evil_1 AC 116 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
constexpr int MAX = 130;
ll A[MAX + 1][MAX + 1];
ll B[MAX + 2][MAX + 2];
int main()
{
    int N, M;
    std::cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        for (int j = 1; j <= M; j++) { std::cin >> A[i][j]; }
    }
    for (int i = 1; i <= M; i++) {
        for (int j = 2; j <= M; j++) { A[i][j] += A[i][j - 1]; }
    }
    for (int i = 2; i <= M; i++) {
        for (int j = 1; j <= M; j++) { A[i][j] += A[i - 1][j]; }
    }
    for (int i = 1; i <= M; i++) {
        for (int j = 1; j <= M; j++) {
            for (int k = i; k <= M; k++) {
                for (int l = j; l <= M; l++) {
                    if (A[k][l] - A[k][j - 1] - A[i - 1][l] + A[i - 1][j - 1] == 0) { B[i][j]++, B[k + 1][j]--, B[i][l + 1]--, B[k + 1][l + 1]++; }
                }
            }
        }
    }
    for (int i = 1; i <= M; i++) {
        for (int j = 2; j <= M; j++) { B[i][j] += B[i][j - 1]; }
    }
    for (int i = 2; i <= M; i++) {
        for (int j = 1; j <= M; j++) { B[i][j] += B[i - 1][j]; }
    }
    for (int i = 0, y, x; i < N; i++) { std::cin >> y >> x, std::cout << B[y][x] << std::endl; }
    return 0;
}
0