結果

問題 No.755 Zero-Sum Rectangle
ユーザー Siqing HouSiqing Hou
提出日時 2018-12-25 17:01:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,323 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 67,892 KB
実行使用メモリ 10,004 KB
最終ジャッジ日時 2024-04-08 22:33:55
合計ジャッジ時間 5,848 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,004 KB
testcase_01 AC 144 ms
6,676 KB
testcase_02 AC 113 ms
6,676 KB
testcase_03 AC 152 ms
6,676 KB
testcase_04 AC 173 ms
6,676 KB
testcase_05 AC 189 ms
6,676 KB
testcase_06 AC 125 ms
6,676 KB
testcase_07 AC 116 ms
6,676 KB
testcase_08 AC 158 ms
6,676 KB
testcase_09 AC 178 ms
6,676 KB
testcase_10 AC 202 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * YukiCoder755.cpp
 *
 *  Created on: Dec 25, 2018
 *      Author: Hou
 */


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>

using namespace std;

int N, M;
long long mat[131][131];
long long sum[131][131];

int main(){
    cin >> N>> M;
    for (int i=1; i<=M; i++)
        for (int j=1; j<=M; j++)
            cin >> mat[i][j];
    sum[0][0] = 0;
    for (int i=1; i<=M; i++){
        sum[i][0] = 0;
        for (int j=1; j<=M; j++)
            sum[i][j] = sum[i][j-1] + mat[i][j];
    }

    for (int j=1; j<=M; j++){
        sum[0][j] = 0;
        for (int i=0; i<=M; i++)
            sum[i][j] = sum[i-1][j] + sum[i][j];
    }

    for (int k=0; k<N; k++){
        int x, y;
        cin >> x>>y;
        int ans = 0;
        for (int x1=1; x1<=x; x1++)
            for (int y1=1; y1<=y; y1++){
                long long s1 = sum[x1-1][y1-1];
                for (int x2=x;x2<=M;x2++){
                    long long s2 = sum[x2][y1-1];
                    for (int y2=y;y2<=M;y2++){
                        long long s3 = sum[x1-1][y2];
                        long long s4 = sum[x2][y2];
                        if (s4-s3-s2+s1 == 0)
                            ans++;
                    }
                }
            }
        cout <<ans <<endl;
    }

	return 0;
}
0