結果

問題 No.755 Zero-Sum Rectangle
ユーザー hiro71687khiro71687k
提出日時 2023-08-03 12:45:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 4,046 ms
コンパイル使用メモリ 255,856 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-21 10:38:25
合計ジャッジ時間 8,959 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,832 KB
testcase_01 AC 105 ms
5,376 KB
testcase_02 AC 85 ms
5,376 KB
testcase_03 AC 114 ms
5,376 KB
testcase_04 AC 136 ms
5,376 KB
testcase_05 AC 145 ms
5,376 KB
testcase_06 AC 96 ms
5,376 KB
testcase_07 AC 89 ms
5,376 KB
testcase_08 AC 123 ms
5,376 KB
testcase_09 AC 132 ms
5,376 KB
testcase_10 AC 152 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=1000000007;
ll inf=10099990;
int main(){
    ll n,m;
    cin >> n >> m;
    vector<vector<ll>>a(m,vector<ll>(m));
    for (ll i = 0; i < m; i++)
    {
        for (ll j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    vector<vector<ll>>b(m,vector<ll>(m));
    for (ll i = 0; i < m; i++)
    {
        b[0][i]=a[0][i];
        b[i][0]=a[i][0];
        if (i>=1)
        {
            b[0][i]+=b[0][i-1];
            b[i][0]+=b[i-1][0];
        }
        
    }
    for (ll i = 1; i < m; i++)
    {
        for (ll j = 1; j < m; j++)
        {
            b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j];
        }
    }
    for (ll i = 0; i < n; i++)
    {
        ll x,y;
        cin >> x >> y;
        x--,y--;
        ll ans=0;
        for (ll j = 0; j <= x; j++)
        {
            for (ll k = 0; k <= y; k++)
            {
                ll z=0;
                if (j>0&&k>0)
                {
                    z+=b[j-1][k-1];
                }
                for (ll l = x; l < m; l++)
                {
                    for (ll o = y; o < m; o++)
                    {
                        ll now=z;
                        if (j>0)
                        {
                            now-=b[j-1][o];
                        }
                        if (k>0)
                        {
                            now-=b[l][k-1];
                        }
                        now+=b[l][o];
                        if (now==0)
                        {
                            ans++;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}
0