結果

問題 No.755 Zero-Sum Rectangle
ユーザー 👑 tatyamtatyam
提出日時 2018-11-18 17:49:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 427 ms / 2,000 ms
コード長 2,775 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 201,076 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 20:44:02
合計ジャッジ時間 9,962 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 312 ms
4,376 KB
testcase_02 AC 237 ms
4,376 KB
testcase_03 AC 350 ms
4,376 KB
testcase_04 AC 347 ms
4,380 KB
testcase_05 AC 315 ms
4,376 KB
testcase_06 AC 235 ms
4,380 KB
testcase_07 AC 275 ms
4,380 KB
testcase_08 AC 427 ms
4,380 KB
testcase_09 AC 338 ms
4,380 KB
testcase_10 AC 325 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
//#define input(a) scanf("%lld", &(a))
//#define output(a) printf("%lld\n", (a))

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
// const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    rep(i, h) {                                                                \
        rep(j, w) cerr << a[i][j] << space;                                    \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

def input() {
    ll A;
    cin >> A;
    return A;
}

ll res, N, M, X, Y, S[131][131];

def culc(ll x1, ll y1, ll x2, ll y2) {
    return S[x1 - 1][y1 - 1] + S[x2][y2] - S[x1 - 1][y2] - S[x2][y1 - 1] == 0;
}

signed main() {
    cin >> N >> M;
    rep(i, M) rep(j, M) cin >> S[i + 1][j + 1];
    rep(i, M) rep(j, M) S[i + 1][j + 1] += S[i][j + 1] + S[i + 1][j] - S[i][j];

    // dump(S, M + 1, M + 1);

    rep(i, N) {
        cin >> X >> Y;
        res = 0;
        rep(x1, M) rep(y1, M) rep(x2, M) rep(y2, M) {
            if (x1 + 1 <= X && X <= x2 + 1 && y1 + 1 <= Y && Y <= y2 + 1) {

                // debug(x1, y1, x2, y2, culc(x1, y1, x2, y2));

                res += culc(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
            }
        }
        cout << res << endl;
    }
}
0