結果

問題 No.755 Zero-Sum Rectangle
ユーザー けーむけーむ
提出日時 2020-06-30 17:27:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,122 ms / 2,000 ms
コード長 1,579 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 171,440 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-10-01 01:32:23
合計ジャッジ時間 8,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,088 KB
testcase_01 AC 1,122 ms
4,380 KB
testcase_02 AC 158 ms
4,380 KB
testcase_03 AC 133 ms
4,500 KB
testcase_04 AC 114 ms
4,376 KB
testcase_05 AC 103 ms
4,380 KB
testcase_06 AC 96 ms
4,376 KB
testcase_07 AC 94 ms
4,376 KB
testcase_08 AC 93 ms
4,376 KB
testcase_09 AC 93 ms
4,376 KB
testcase_10 AC 94 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> a(m, vector<ll>(m));
    rep(i, m) rep(j, m) cin >> a[i][j];
    vector<ll> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    vector<vector<ll>> dp(m + 1, vector<ll>(m + 1, 0));
    rep(i, m) rep(j, m) dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j] + a[i][j];
    vector<ll> ans(n, 0);
    rep(sx, m) {
        rep(sy, m) {
            reps(gx, sx, m) {
                reps(gy, sy, m) {
                    ll v = dp[gx + 1][gy + 1] - dp[gx + 1][sy] - dp[sx][gy + 1] + dp[sx][sy];
                    if (v == 0) {
                        rep(i, n) {
                            if ((sx <= x[i]) && (gx >= x[i]) && (sy <= y[i]) && (gy >= y[i])) {
                                ans[i]++;
                            }
                        }
                    }
                }
            }
        }
    }
    rep(i, n) cout << ans[i] << endl;
    return 0;
}
0