結果

問題 No.755 Zero-Sum Rectangle
ユーザー polyomino_24polyomino_24
提出日時 2018-12-06 02:46:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,974 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 880 ms
コンパイル使用メモリ 99,880 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-11 14:02:22
合計ジャッジ時間 24,490 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1,930 ms
4,352 KB
testcase_02 AC 1,914 ms
4,348 KB
testcase_03 AC 1,951 ms
4,348 KB
testcase_04 AC 1,960 ms
4,348 KB
testcase_05 AC 1,953 ms
4,348 KB
testcase_06 AC 1,911 ms
4,348 KB
testcase_07 AC 1,921 ms
4,352 KB
testcase_08 AC 1,974 ms
4,356 KB
testcase_09 AC 1,946 ms
4,368 KB
testcase_10 AC 1,955 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll sum[135][135];
int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m){
        rep(j,m){
            cin >> sum[i][j];
        }
    }
    rep(i,m)rep(j,m)sum[i][j+1] +=sum[i][j];
    rep(i,m)rep(j,m)sum[i+1][j] +=sum[i][j];
    
    while(n--){
        int x,y;
        cin >> x >> y;
        x--,y--;
        int ans =0;
        rep(a,m)for(int b = a; b < m; b++)rep(c,m)for(int d = c; d < m; d++){
            ll s = sum[b][d];
            if(a>0)s -= sum[a-1][d];
            if(c>0)s -= sum[b][c-1];
            if(a>0 and c > 0) s+=sum[a-1][c-1];
            if(a<=x and x <= b and c<= y and y<=d and s == 0)ans++;
        }
        cout << ans << endl;
    }
}
0