結果
| 問題 | No.755 Zero-Sum Rectangle | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-08-02 16:28:21 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 136 ms / 2,000 ms | 
| コード長 | 1,193 bytes | 
| コンパイル時間 | 922 ms | 
| コンパイル使用メモリ | 75,100 KB | 
| 最終ジャッジ日時 | 2025-01-12 13:26:20 | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 11 TLE * 1 | 
ソースコード
#include <iostream>
#include <vector>
template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
using lint = long long;
void solve() {
    int n, m;
    std::cin >> n >> m;
    auto sums = vec(m + 1, vec(m + 1, 0LL));
    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= m; ++j) {
            lint x;
            std::cin >> x;
            sums[i][j] = x + sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1];
        }
    }
    auto get = [&](int lx, int ly, int rx, int ry) {
        return sums[rx][ry] - sums[rx][ly - 1] - sums[lx - 1][ry] + sums[lx - 1][ly - 1];
    };
    while (n--) {
        int sx, sy;
        std::cin >> sx >> sy;
        int ans = 0;
        for (int lx = 1; lx <= sx; ++lx) {
            for (int ly = 1; ly <= sy; ++ly) {
                for (int rx = sx; rx <= m; ++rx) {
                    for (int ry = sy; ry <= m; ++ry) {
                        if (get(lx, ly, rx, ry) == 0) ++ans;
                    }
                }
            }
        }
        std::cout << ans << "\n";
    }
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
    return 0;
}
            
            
            
        